Old 30th January 2014, 19:52   #1
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
Install does not continue after reboot

I have written an installer script which checks to be sure the user has admin privileges before doing anything. If the user has admin rights, the script then checks whether a previous version of my app exists. If one exists, the previous version is removed, an executable installer for the new version is copied to a temp directory, and a 'RunOnce' registry key is set. Then the system is rebooted. Installation of the new version continues when the OS encounters the RunOnce key after the reboot. This all works fine.

However, if the user does not have admin privileges AND the UAC controls are set up at a restrictive level, then the OS interrupts this process. Example: 'Joe User' (not an admin) starts the installer. Before my own check to determine whether Joe User has admin rights, the OS interrupts with a UAC dialog requesting credentials from someone with admin rights (say, 'John Admin'). If they are supplied, then the install proceeds normally, up to and including the reboot. However, after rebooting, Joe User logs back on. The installation will not continue because the 'RunOnce' key was written into the registry for 'John Admin'. If 'John Admin' does happen to log on at any subsequent time, the installation will continue.

How do I keep this from happening?

Thanks!
Austin71 is offline   Reply With Quote
Old 30th January 2014, 20:21   #2
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Use HKLM instead of HKCU.
jpderuiter is offline   Reply With Quote
Old 30th January 2014, 21:44   #3
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
Question

I am currently writing to:

HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce

I think it should work regardless of who logs in, but it doesn't seem to. If 'Joe User' logs in after the reboot, nothing happens. If I subsequently do a "switch user" to 'John Admin', it fires off the RunOnce key as soon as John Admin logs on.
Austin71 is offline   Reply With Quote
Old 31st January 2014, 06:39   #4
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Do you copy the installer to a user dependent temp folder maybe?
jpderuiter is offline   Reply With Quote
Old 31st January 2014, 14:49   #5
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
That is excellent, I didn't think about that.

I create a folder under the "$TEMP" directory and put it there, like this:

StrCpy $TempPath "$TEMP\MyAppName"
CreateDirectory $TempPath
SetOutPath $TempPath
File "c:\InstallerExecutable.exe"


The documentation says that $TEMP will most likely point to "C:\Windows\Temp" but I tested it, and the above script creates this folder:

"C:\Users\John Admin\AppData\Local\Temp\MyAppName".

So this does appear to go to a user dependent Temp folder. Can you suggest a better place for this to go?
Austin71 is offline   Reply With Quote
Old 31st January 2014, 20:50   #6
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
I tried something that I thought might work, but it failed. Instead of writing the executable to a subdirectory of $TEMP, I created a folder under $APPDATA\Temp, then changed that folder's permissions, like this:

SetShellVarContext all
StrCpy $TempPath "$APPDATA\Temp\MyAppName"
CreateDirectory $TempPath
AccessControl::GrantOnFile "$TempPath" "Everyone" "GenericRead + GenericExecute + Delete"
SetOutPath $TempPath
File "c:\InstallerExecutable.exe"


With UAC controls set high, I logged in as Joe User. UAC quickly requested admin credentials, so I supplied John Admin. The installation went OK until after the reboot. Upon rebooting, I logged in again as Joe User (as Joe User might do). The RunOnce key was set correctly in HKLM, and the executable was waiting to be run in $APPDATA\Temp\MyAppName. I checked the permissions for that folder and they were set correctly. Yet it did not fire off. Then, I "switched user" to John Admin, and the RunOnce key immediately ran the executable. Can you see anything I've done wrong?

Thanks
Austin71 is offline   Reply With Quote
Old 2nd February 2014, 02:36   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,217
The RunOnce key only works for administrators.

Since there can be more than one admin on a machine you don't know which of them is going to log in so you should store your state somewhere global.

I'd suggest $windir\Temp or if you use "SetShellVarContext all" $appdata\yourcompany will map to c:\programdata\yourcompany

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd February 2014, 17:13   #8
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
I'm afraid I don't quite understand what you mean by "store your state somewhere global". I put my executable in the user-independent location $APPDATA\Temp\MyAppName, but if the RunOnce key only works for administrators, doing so does not completely solve my problem.

I think the problem is that UAC sort of "hijacks" the install process. If Joe User logs in and tries to install my app, I can warn him to go get an admin to perform this, and also to have that same admin log in after the reboot, to complete the install. But if UAC is set high, then it immediately asks for admin credentials before my installer can advise the user what needs to be done. How is this generally handled? Or should I just assume that an administrator will be the one installing the software and will know how to complete the process (by logging in again after the reboot)?
Austin71 is offline   Reply With Quote
Old 4th February 2014, 14:35   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,217
If you absolutely have to be admin to complete the install maybe if some non-admin user runs your app before the install is complete you can prompt them to log in as admin or spawn the RunOnce commandline yourself...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th February 2014, 19:21   #10
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
I think is a good suggestion to prompt them for an admin. I believe that I must have an admin because I am writing information into the HKLM, changing permissions in the Program Data\MyApp folder, and installing the app for "all users".

Thanks very much. Maybe I am trying to cover too many bases.
Austin71 is offline   Reply With Quote
Old 5th February 2014, 01:30   #11
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,217
Why can you not do these things before the reboot?

Why do you have to reboot anyway?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 5th February 2014, 15:03   #12
Austin71
Junior Member
 
Join Date: Jan 2014
Posts: 7
Well perhaps there is a flaw in my thinking. Here is what I am doing:

My installer installs my app and some associated hardware drivers. When the installer runs, it checks for the existence of a previous version. If it finds one, it uninstalls it as well as the hardware drivers. However it is my understanding that it is not possible to install new hardware drivers until after a reboot. That is why I am going to all this trouble. Does it sound correct that this would be the case?
Austin71 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
install, reboot, uac

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump