我已经评论说:“将程序设置写入注册表不是给予您应用程序管理权限的正确原因”。不过,在任何情况下都包含UAC清单是一个好主意。常见的requestedExecutionLevel
应该是level="asInvoker"
。 see the docs
"Q: Adding manifest for admin rights request for delphi 7"
创建以下4个文件(2台):
(UAC只)
uac.manifest
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="MyApp" type="win32"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
uac。RC
1 24 "uac.manifest"
(UAC + XP主题)
uac_xp.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="MyApp" version="1.0.0.0" processorArchitecture="x86"/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<!-- Windows Vista application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--Windows 7-->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--Windows Vista-->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
</assembly>
uac_xp.rc
1 24 "uac_xp.manifest"
通过所需rc
文件(uac.rc
或uac_xp.rc
)添加到您的项目 “项目>添加到项目” 菜单项。这将在您的项目文件中创建的{$R}
指令:
program Project1;
{.$R 'uac.res' 'uac.rc'} // UAC only
// OR
{$R 'uac_xp.res' 'uac_xp.rc'} // UAC + XP Themes
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
注意{$R 'uac_xp.res' 'uac_xp.rc'}
。 Delphi会自动编译rc
到res
文件。
或者,您可以通过Delphi IDE外的brcc32 uac.rc
编译rc
文件。然后手动将{$R 'uac_xp.res'}
添加到您的项目中。
请确保您不使用任何其他XP清单。
将程序设置写入注册表并不是给您的应用程序管理员权限的正确原因!这是一个非常糟糕的主意。 – kobik
人们不知道为什么你不做其他开发人员所做的,并将程序设置写入正确的位置。 –
我正在将它们写入Hkey当前用户,从我阅读的内容来看,它应该可以在没有管理员的情况下写入。 – Clinton