rajat
rajat

Reputation: 3553

Execute a command using NSIS

i want to execute some commands using NSIS script , but for the commands to work i have to open command prompt using "run as administrator" from the right click menu . How do it do it using NSIS script .

I am using

 RequestExecutionLevel admin 

along with the exec command but this does not seem to work .

Upvotes: 3

Views: 884

Answers (1)

Anders
Anders

Reputation: 101569

RequestExecutionLevel only works on Vista+ when UAC is on so you should also check at run-time to cover the other cases:

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

Upvotes: 3

Related Questions