//以管理员身份运行
procedure RunAsAdmin(hWnd: HWND; aFile: string; aParameters: string);
var
sei: TShellExecuteInfoA;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
sei.lpVerb := \'runas\';
sei.lpFile := PChar(aFile);
sei.lpParameters := PChar(aParameters);
sei.nShow := SW_SHOWNORMAL;
if not ShellExecuteEx(@sei) then
RaiseLastOSError;
end
//把按钮设置成需要管理员运行样式,也就是加个图标到按钮上
procedure SetElevationRequireState(aControl: TWinControl; Requiered: Boolean);
const
BCM_FIRST = $1600;//Button control messages
BCM_SETSHILED = BCM_FIRST + $000C;
var
lRequired: Integer;
begin
lRequired := Integer(Requiered);
SendMessage(aControl.Handle, BCM_SETSHIELD, 0, lRequired);
end;