tags:

views:

136

answers:

1

for delphi,

I want to run my application with admin rights on vista or win 7 is there a solution for this you may know ?

related question:

http://stackoverflow.com/questions/3300390/want-to-learn-if-my-application-has-admin-rights

thanks.

+2  A: 

Hello, 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;
Aldo