Archive: install all files after reboot


install all files after reboot
Hi All,
I've looked through the various nsis help resources and haven't found a possible way to do the following:

I would like to install all the files for our application (jars, jpgs, etc) after reboot if we determine such is necessary. This is somewhat similar to what installlib does but its' not only for dlls in use. We have some logic that determines if we need to reboot or not, and we want to set it up so that the files are automatically copied after the reboot.

And we don't want to force the user to reboot.

So if a reboot is necessary, the files will not be copied over. When the system is rebooted, potentially at a later time, then the files should be copied upon reboot.

Is this possible using NSIS?
Thanks.


You could create a temporary copy of your installer at some place on the user's HDD and then create an entry for your installer in the Registry at the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce


The installer will be launched next time the user boots up his system. You can also pass some commandline args to your installer, so the installer knows that it's time to complete the install now (instead of restarting from the beginning) ...

It's probably better to copy the files to a temp folder and use

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager -> PendingFileRenameOperations


Running an installer on reboot in Vista with UAC on, will pop-up a message asking the user for permission. If user cancels, installation isn't complete...

[RANT]Vista does a good job to make the lives of both, developers and users, harder ;)
I'll stick with XP x64 and Ubuntu ... [/RANT]

Then maybe register the installer at:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run


This will run the installer every time the system boots up, unless it's removed form that key again. So the installer could remove itself from the key if (and only if) setup was completed successfully. If the user aborts the setup, next reboot will offer a new attempt to complete the installation...

Originally posted by LoRd_MuldeR

Then maybe register the installer at:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

That's even worse if the installer must run as admin, since Windows Defender which is installed by default blocks applications that appear in this reg key ;)

Maybe the best way is to put in Run or RunOnce an installer with user permissions that won't be blocked by Defender and won't pop-up UAC. It will show it's own friendly dialog informing the user of the resume, and only then run an admin process to copy the files (using UAC_plug-in maybe).

I'm trying to do the same thing myself now.

As BuilderBob suggest let the PendingFileRenameOperations do the job. You can do so by using the Rename instruction with /REBOOTOK flag in NSIS.

E.g.

; Extract your file in temp directory
File "/oname=$TEMP\file.tmp" somefile.ext

; Rename (move) your file to the destination. If the destination file already exist
; the file will be moved when the system reboots via PendingFileRenameOperations
Rename /REBOOTOK $TEMP\file.tmp $INSTDIR\somefile.ext


You can also use PendingFileRenameOperations by invoking MoveFileEx() api with the system plug-in, but I think the Rename method is better cause it also works in Windows 9x / ME.

PaR

I don't think the Rename /REBOOTOK works for me because it delays the rename only if the file handle is in use. In my scenario it could be the case that just 1 file might be in use and i want to to delay the rename operations for all the other files as well.

Looks like the movefileex api allows you to specify a flag to delay renames until reboot so that might work.

Thanks for the help.


Originally posted by BuilderBob
That's even worse if the installer must run as admin, since Windows Defender which is installed by default blocks applications that appear in this reg key ;)
:eek:

How can they do that? Most programs that need to run at system startup, such as "agents" and background processes, register themselves there. Blindly blocking all those processes will break the functionality of MANY applications, that's for sure...

Originally posted by LoRd_MuldeR
:eek:
Most programs that need to run at system startup, such as "agents" and background processes, register themselves there.
I forgot to write that only those that require admin premissions (in it's Vista manifest, or have no manifest), will be blocked. Also, services are different. You can google "defender" + the Run reg key and find workarounds.

Originally posted by vijaym
I don't think the Rename /REBOOTOK works for me because it delays the rename only if the file handle is in use.
Actually NSIS manual clearly states that the rename is delayed when the file already exist and it doesn't need to be in use. :)

"The destination file must not exist or the move will fail (unless you are using /REBOOTOK). If /REBOOTOK is specified, and the file cannot be moved (if, for example, the destination exists), then the file is moved when the system reboots."
PaR

I think vijaym means that "Rename /REBOOTOK" works on single files. If you rename 10 files and 5 of them are currently locked, then 5 files are renamed and 5 files will be renamed on next reboot. What he wants: Either rename all files or (if only one of them is locked) delay all 10 files until next reboot...