1

I am opening a file using the installer script nsis and i need to open it as an admin in order for it to run properly, but i cannot seem to figure out how to do this.

currently my open code looks like this:

FileOpen $4 "$R0" w
FileRead $4 $1
FileClose $4

it opens it but as a regular user and i need it to be as an admin. is there a way to do this?? thanks in advance for your help!

Anders
  • 97,548
  • 12
  • 110
  • 164
ph_leh
  • 271
  • 1
  • 3
  • 5

1 Answers1

4

You cannot open a file as a different user in a normal application. If you need this kind of power the whole installer probably needs to run elevated:

Outfile RequireAdmin.exe
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)

!include LogicLib.nsh

Function .onInit
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
    MessageBox mb_iconstop "Administrator rights required!"
    SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
    Quit
${EndIf}
FunctionEnd

Page InstFile

Section
SectionEnd
Community
  • 1
  • 1
Anders
  • 97,548
  • 12
  • 110
  • 164
  • That's true: one process has only one security token during its entire life. So either a process has administrator privileges or it doesn't have them. – Alexey Ivanov May 27 '12 at 07:32
  • I am trying to get the same effect as right clicking on the file and choosing run as administrator. – ph_leh May 29 '12 at 13:12