Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 .

like image 753
rajat Avatar asked Jul 29 '26 05:07

rajat


1 Answers

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
like image 129
Anders Avatar answered Aug 01 '26 05:08

Anders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!