Archive: NSIS-made autorun (user mode) needs to call NSIS-made setup (admin mode)


NSIS-made autorun (user mode) needs to call NSIS-made setup (admin mode)
Pretty much it is the subject, in a nutshell. I have taken a script my company has been using for making nifty autorun programs for CDROMs that allow users to install program, view readme, and exit the autorun. I've made some changes for additional options and all was well with our world until Vista came around.

As is, the autoruns wanted Admin rights, so I included "RequestExecutionLevel User" for the autorun and "RequestExecutionLevel Admin" for the setup. The relevant code for the autorun is as follows:

  Call CheckInstallStatus ; We are paranoid... The user may have (un)installed it behind our backs...
StrCmp $InsStat "1" +1 +5 ; Check Installation Status
SetOutPath "$INSTDIR"
Exec "$INSTDIR\${PROGEXE}" ; Run installed program
SetOutPath "$EXEDIR"
Goto +5
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R0 $R0 1201 # 1201 is field 2
SendMessage $R0 ${WM_SETTEXT} 0 "STR:Please wait while the program installs..."
ExecWait "$EXEDIR\setup.exe" ; Run installer
Call InstallRunButton ; Run script that controls button messages.
Abort ; Return to the page

I believe the issue is that the user-access autorun is not liking to be told to run an admin-access setup. What do I need to do to get this to work properly? I've seen a mention of "UAC::ShellExecWait", but have not been able to track down specifics if this is a plugin or how to use it.

Thanks for the help here. Great community. :)

Ergh. Found something through the wiki. Going to work on the UAC plug-in to see if this can solve my issue, but if someone else has another workaround, or can confirm my suspicions, I would appreciate it.


Exec (CreateProcess internally) can not elevate, it will just return with a ELEVATION_REQUIRED error. ExecShell(ShellExecute internally) on the other hand should work. NSIS does not have a wait version of shellexec so if you really have to wait you can use the UAC plugin, try
UAC::ShellExecWait "" SW_SHOWNORMAL '"$EXEDIR\setup.exe"'


From what I have read with the UAC plugin, it will run both the admin and user levels simultaneously, correct? That doesn't quite solve the problem, since I am trying to avoid forcing the prompt for Admin upon insertion of the CD into the computer.

I guess the ExecShell should be sufficient, although I would prefer the wait statement...

Vista does things right (finally) with the UAC, but just wish it wouldn't get in the way so often. :P


no, the UAC plugin works in two modes, if you have not called UAC::RunElevated (or user failed to elevate and you ignore this error) all other UAC:: calls should perform without elevation (with the current user profile and privileges)

Or atleast, thats how its supposed to work


I meant that the autorun program would have to prompt for the admin access upon init of the autorun program, which would be when the CD is inserted into the computer.

Or do you mean to put the UAC in the main setup NSIS program?


What I mean is, the autorun program will run without admin access, the setup will run as admin, but you would not use the UAC stuff to handle elevation (unless you want to), you would only use the UAC plugin because it should be able to give you a working shellexecwait (I just tested on my own machine, and I can't actually get it to work) If you join the #nsis irc channel I might be able to give you some progress report on fixing this


Nevermind, I just forgot the two last parameters ;)

try:
UAC::ShellExecWait "" SW_SHOWNORMAL '"$EXEDIR\setup.exe"' "" ""


Again, thanks for the help. The UAC plugin wiki doesn't appear to have info on this, as most of the examples instruct on how to downgrade the user access rather than the vice-versa.


Yeah, it is sort of undocumented, but the UAC plugin is hard enough to explain as it is, I'm not sure if I want to create more confusion with the fact that most of the exported functions should work even if you don't call UAC::RunElevated first