Delphi生成EXE自动以管理员身份运行
【测试环境】Windows 7 旗舰版 With Sp1,RAD 10 Seattle
1、文本文件:UAC.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"> </requestedExecutionLevel> </requestedPrivileges> </security> </trustInfo> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"> </assemblyIdentity> </dependentAssembly> </dependency> </assembly>
2、文本文件:UAC.rc
1 24 UAC.manifest
3、拷贝上述两个文件到RAD10目录下/bin(如Embarcadero\Studio\17.0\bin)
4、用brcc32编译这个.rc文件为.res文件
brcc32 uac.rc -fouac.res
5、在工程文件.dpr中{$R *.res}后面加入{$R uac.res}
6、打开工程属性,Application->Manifest File,改成Custom,在下方选择UAC.manifest文件,重新编译工程。