本文整理自网络,侵删。
方法一: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"/>
</requestedPrivileges>
</security>
< /trustInfo>
< /assembly>
2、编辑文件uac.rc,内容如下:
1 24 UAC.manifest
3.将rc文件编译为res文件:
brcc32 UAC.rc //brcc32 在delphiX\Bin目录下
4、函数过程及编译参数:
{$R uac.res}
function RunAsAdmin(hWnd: hWnd; filename: string; Parameters: string): Boolean;
{
See Step 3: Redesign for UAC Compatibility (UAC)
http://msdn.microsoft.com/en-us/library/bb756922.aspx
}
var
sei: TShellExecuteInfo;
begin
ZeroMemory(@sei, SizeOf(sei));
sei.cbSize := SizeOf(TShellExecuteInfo);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
sei.lpVerb := PChar('runas');
sei.lpFile := PChar(filename); // PAnsiChar;
if Parameters <> '' then
sei.lpParameters := PChar(Parameters); // PAnsiChar;
sei.nShow := SW_SHOWNORMAL; //Integer;
Result := ShellExecuteEx(@sei);
end;
方法2: 最新版的DELPHIxe 自带选项如图设置:

相关阅读 >>
Delphi 判断一个数组的长度用 length 还是 sizeof ?
Delphi sccoloredid,星际争霸彩色 id 修改器 v0.2.0,支持 windows vista
更多相关阅读请进入《Delphi》频道 >>