It is the same way recommended by Microsoft. Small working example for self-elevation:Inf0Byt3 wrote:Here's the code that I use in the install maker to re-launch the installer EXE and gain administrator rights:
http://www.purebasic.fr/english/viewtop ... shExecInfo
To actually gain the rights to write to Program Files, you'll need to explicitly right click your executable and select "Run as Administrator" from the context menu. That should work in theory.
Code: Select all
If ProgramParameter(0)<>"-admin"
;
; main program
;
MessageRequester("INFO","USER MODE")
FileName.s = ProgramFilename()
Info.SHELLEXECUTEINFO
Info\cbSize = SizeOf(SHELLEXECUTEINFO)
Info\lpVerb = @"runas"
Info\lpFile = @FileName
Info\lpParameters = @"-admin"
Info\nShow = #SW_SHOW
ShellExecuteEx_(@Info)
Else
; dialog for admin mode
MessageRequester("INFO","ADMIN MODE")
EndIf