accessing the program files directory

Just starting out? Need help? Post your questions and find answers here.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: accessing the program files directory

Post by Danilo »

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.
It is the same way recommended by Microsoft. Small working example for self-elevation:

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