delphi程序在Win7 win8 win10下自动请求以管理员身份运行  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi程序在Win7 win8 win10下自动请求以管理员身份运行


方法一:1、编辑文件UAC.manifest,内容如下:
 
< assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">     
< trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
        
            
                
           
 
       
 
< /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 自带选项如图设置:


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.12242293357849 seconds