开发者

How to launch an application with admin rights?

开发者 https://www.devze.com 2023-01-08 01:10 出处:网络
for delphi, I want to run my application with admin rights on vista or w开发者_JS百科in 7 is there a solution for this you may know ?

for delphi,

I want to run my application with admin rights on vista or w开发者_JS百科in 7 is there a solution for this you may know ?

related question:

Want to learn if my application has admin rights?

thanks.


To run a program with admin rights I have this function which has worked for me so far.

procedure RunAsAdmin(const aFile: string; const aParameters: string = ''; Handle: HWND = 0);
var
  sei: TShellExecuteInfo;
begin                   
  FillChar(sei, SizeOf(sei), 0);

  sei.cbSize := SizeOf(sei);
  sei.Wnd := Handle;
  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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号