Archive: admin right to set up


admin right to set up
How can I make sure the user installing my software has admin rights as i am making setup using Nsis scripting language, and should applicable for all OS (Windows,XP).


1) In .onInit, use the UserInfo plugin to verify admin access. If it's not admin, throw a messagebox error and quit.
2) To allow Vista/7 UAC to handle things more gracefully, you may also want to add 'requestexecutionlevel admin' to your script.


Thanks MSG for your reply
how can i use the userinfo plugin ,can you provide me any link or any code help where i can get all the details


Hmm... Try googling for 'nsis userinfo plugin'. Also, the userinfo plugin comes shipped with NSIS, so check NSIS\Examples\UserInfo\UserInfo.nsi .

As you can see, all the information is out there. You just need to be brave enough to search for it, before asking others for the solution.


http://pastebin.com/EvMkyLLt


Say Anders, does Windows automatically set an errorlevel if UAC elevation fails?


Originally posted by MSG
Say Anders, does Windows automatically set an errorlevel if UAC elevation fails?
Errorlevel is really a DOS/batch thing, windows processes have exit codes.

Most of the elevation operation takes place in the parent process (ShellExecuteEx calls the UAC service, that service probably calls CreateProcessAsUser or something like that) If the error happens there, ShellExecuteEx would return false and you would call GetLastError to get the error code (No process was created so there is no process exit code) You can get ERROR_CANCELLED etc from GetLastError.

It is also possible to get a process that dies early (never really gets started, missing dll import etc) with a valid SHELLEXECUTEINFO.hProcess, you could call GetExitCodeProcess on that handle and get a process exit code. ShellExecuteEx would return true here since it did actually start the process, the problem is with the child process. What the exit code is would be up to the windows loader, c runtime or the code in WinMain depending on where the error happens or if the process runs as normal.

As far as NSIS goes, ExecShell will set the error _flag_ if it fails but there is no way to get the actual error code from ShellExecute without calling it directly with the system plugin...

Err yeah, exit code. Very informative, thank you!


Thanks Anders for your help
i made changes it and run on both XP and Vista system but only the difference is that in Xp message box is shown "Administrator rights required!" but in vista no message box is coming with the same code,as you have provided in the link waiting for the reply
============================================
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

Section
SectionEnd


Originally posted by MSG
Hmm... Try googling for 'nsis userinfo plugin'. Also, the userinfo plugin comes shipped with NSIS, so check NSIS\Examples\UserInfo\UserInfo.nsi .

As you can see, all the information is out there. You just need to be brave enough to search for it, before asking others for the solution.
Thanks MSG

Originally posted by shazia.parveen
in Xp message box is shown "Administrator rights required!" but in vista no message box is coming
Then that probably means that you're already an admin user, on your Vista PC.

Hi Msg actually after running the setup with no admin right account only it is showing the login page for administrator to login for administrative right it is not showing the message box "Administrator rights required!" in Vista as it was showing in Xp.

Actually when i turned off UAC in case of Vista then it is showing the message box "Administrator rights required!" but when UAC is turned on in case of Vista no message box is coming only it is showing the login page for administrator .


In no admin right account when i turned off UAC in case of Vista then it is showing the message box "Administrator rights required!" but when UAC is turned on in case of Vista no message box is coming only it is showing the login page for administrator . waiting for the reply.


It's doing exactly what it should - this is how UAC is designed to operate. There is nothing you can do about it.


If you always want the messagebox, use "RequestExecutionLevel user" (There is no reason to do this, and the exe will not get the UAC icon overlay)


Not only is there no reason to do that, but it also makes things worse: Many users don't know how to 'Run as Admin', because they rely on UAC to do the elevation for them. If you request user, and then enforce admin, many people won't understand how to use the installer.


Thanks so much for your support