English 中文(简体)
由C++/CLI[复制]担任管理人
原标题:Run as administrator by C++/CLI [duplicate]

I m writing a tweak utility that modifies some keys under HKEY_CLASSES_ROOT.

All works fine under Windows XP and so on. But I m getting error Requested registry access is not allowed under Windows 7. Vista and 2008 I guess too.

How should I modify my code to add UAC support?

最佳回答

app.manifest should be like this:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <security>
         <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
         </requestedPrivileges>
      </security>
   </trustInfo>
</asmv1:assembly>
问题回答

You can t write to the HKCR (or HKLM) hives in Vista and newer versions of Windows unless you have administrative privileges. Therefore, you ll either need to be logged in as an Administrator before you run your utility, give it a manifest that says it requires Administrator level (which will prompt the user for Admin login info), or quit changing things in places that non-Administrators shouldn t be playing. :-)

如果你不需要全方位的行政管理,或只需要少数不定期的改动,你就可以改变一个新过程,并采用:

Process.StartInfo.UseShellExecute = true;
Process.StartInfo.Verb = "runas";

它将管理这一过程,以在登记处做你们所需要的一切,但以正常的主人的身份回到你身上。 这样,每当用户发射一次UAC dialog时,就不必这样做。

作为一种临时固定装置,用户可以正确点击公用事业,选择“Run”作为管理人。

我正在尝试<代码>verb = “runas”,但我仍在试图更新登记价值时获得未经许可的AccessException。 改头是因为没有开标子,可以记实。

Registry.OpenSubKey("KeyName", true);

Cannot 致书记官处钥匙,获得未经许可的AccessException

您 ...... 如同Abatishchev一样,但是没有UAC

<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
   <security>
    <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>




相关问题
how to reliable capture display setting changed

static void Main() { // Set the SystemEvents class to receive event notification when a user // when display settings change. SystemEvents.DisplaySettingsChanged += new ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

Statically linking Winsock?

I m using Winsock 1.1 in my project. I include wsock32.lib in "Additional Dependencies". I m looking at the DLL project using depends.exe and notice that the DLL depends on wsock32.dll. How can I ...

热门标签