Archive: NSIS.Library.RegTool.v2.exe is queued for delete by previous setup reboot


NSIS.Library.RegTool.v2.exe is queued for delete by previous setup reboot
I run my setup and it says reboot is required. In registry there is a RunOnce entry to execute "c:\WINDOWS\System32\NSIS.Library.RegTool.v2.exe /S".
There is also a registry entry HKLM\SOFTWARE\NSIS.Library.RegTool.V2\ with entries of dlls to register on boot

After reboot, the RunOnce and associated SOFTWARE\NSIS.Library registry entries go away, and my app is installed and ready to go.

There now is an entry in "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" called "PendingFileRenameOperations" with value data
saying to delete C:\WINDOWS\System32\NSIS.Library.RegTool.v2.exe

If I run setup again, the RunOnce entry is added but the PendingFileRenameOperations is still there.

On reboot, windows puts up a message box saying it cannot find C:\WINDOWS\System32\NSNS.Library.RegTool.v2.exe so
the second install does not complete.

Help!


Is rebooting twice not considered a problem?
Run installer, which requires reboot, then after reboot install something else which requires reboot, then during that reboot windows cannot find NSIS.Library.RegTool.v2.exe, because previous reboot put NSIS.Library.RegTool.v2.exe in the PendingFoleRenameOperations list so it was deleted before the RunOnce tried to complete the second setup.

Am I doing something wrong? Using NSIS 2.10


You're not doing anything wrong. There's a problem with files that are queued for deletion and then used again.

I'm tempted to put RegTool in the temporary directory and just leave it there. It's very small, and will be even smaller without the deletion on reboot queueing code. Any comments?


I have no problem with leaving the file around at all. Is there a script file i can edit to make this happen?

Or, it could be arranged that any time the regtool is added to RunOnce, any PendingFileRenameOperations entry for it could be removed so the RunOnce will get to run. Then you still have the delayed cleanup of regtool on the next boot (unless someone runs another nsis based install)


The PendingFileRenameOperations entry is not documented properly anywhere at MSDN. I don't think it'd be a good idea to mess with it.

To get RegTool to not delete itself and write to the temporary directory a few source changes needs to be made. In attach ZIP, you'll find a patch for the source code, the complete Library.nsh with the change and a compiled version of RegTool. Please test it and let me know how it goes.

If it does work, we need to consider what to do with older versions. The easiest solution would probably be bumping the version. This way, nothing bad will happen in the rare-chance that some DLL is installed to the temporary directory, which will cause the RegTool to be deployed there.


The Regtool.bin worked correctly. When I was putting the changes into my nsis installation, I did my usual diff of the changed files. Library.nsh changed the file location of regtool to $TEMP, but did not change the RunOnce entry, it still used $R2. I tried it as is anyway, and of course it could not find regtool on second setup reboot. The $TEMP is in my user directory localsettings. Instead of changing the RunOnce entry in the changed Library.nsh, I reverted to the old 2.10 one. I have no problem with the exe being left in winsys. My own uninstalls do not remove my common dlls from there either. Not an issue for me, though I will follow however you decide (presumably in 2.11)

Everything works fine! Thanks very very much!


Keeping it in $SYSDIR would be a problem, because the path it's kept in is not always $SYSDIR. It's actually the path of the first installed DLL. This could leave over a lot of copies of the tool.


Could the Library.nsh use a "random" (GUID) file name, like it does for the entries under the HKLM\Software\NSIS.Library.RegTool.v2, for the name of the exe it deposits in $R2 or $TEMP, and adds to RunOnce ?

If the regtool can figure out its exe file name and do the MoveFileEX to delete on next boot, it can be safely deleted, since another run of setup would extract it with a different filename for RunOnce to find.


Originally posted by kichik
I'm tempted to put RegTool in the temporary directory and just leave it there. It's very small, and will be even smaller without the deletion on reboot queueing code. Any comments?
why cant RegTool just delete itself when its done?

Originally posted by Anders
why cant RegTool just delete itself when its done?

Can't delete a running executable. The best solution would be a way for a process to tell windows "wait until I exit, then delete me".

This works:

1. Use the original Program Files\NSIS\bin\RegTool.bin, it figures out its filename and tells windows to delete it on next reboot.

2. Change Program Files\NSIS\Include\Library.nsh :
Change lines

File /oname=$R2\NSIS.Library.RegTool.v2.exe "${NSISDIR}\Bin\RegTool.bin"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
"NSIS.Library.RegTool.v2" '"$R2\NSIS.Library.RegTool.v2.exe" /S'

to
File /oname=$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
"NSIS.Library.RegTool.v2" '"$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe" /S'

Changed version attached.

The RegTool program gets a unique name, and RunOnce key knows to run it. After reboot regtool has run and there will be a pending delete of that file for the next boot. Another setup run before next boot will set up RegTool with a different .exe name and RunOnce entry, and on boot the old RegTool is deleted but the new one is still there and it runs (queuing itself for delete on next boot). I think any number of setups could be run with reboots between or not.


Quote:


Originally posted by Anders
yes it is possible, its a bit of a hack but it IS possible

http://www.catch22.net/tuts/selfdel.asp
http://www.nsonic.de/Delphi/txt_WIS00561.htm
I didn't know about those, but never assumed it not possible. But from qa quick look at these links, the ones that truly delete from a running system do not guarantee to work in future version. Which would anser original question as to why regtool does not just delete itself. Really should be O/S support for something like that.

Cool though!

Oops...

Testing with a few setups in a row did not work. You can only have one key with the same name in registry, it seems.
Had to add unique id to value name in runonce.

There is a test that tries to see if RunOnce file already exists, but it is ineffective, because RunOnce value has the /S on the end, so the filename will never exist, so we create a new unique named file but can only add one of these to RunOnce (the last one is the one preserved, I think)

In Library.nsh change to:
;Setup RegTool

ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID"
IfFileExists $R3 +3

File /oname=$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
"NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID" '"$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe" /S'


This works for multiple setups betweem reboots. No regtools left after reboot after last install's reboot.

Changed Library.nsh attached.


There's no need to deploy more RegTools. Each one does the work for them all. The test just needs to be adjusted. This, after ReadRegStr, should do:

StrCpy $R3 $R3 -4 1
It would be possible to extract the RegTool with a unique name to avoid the original issue. It would also help avoid the temporary directory which users like to mess with.

Here's what I ended up uploading. It uses the original RegTool. Let me know if there are any problems with it.


I diffed with the last one.
Shouldn't the line

File /oname=$R2\NSIS.Library.RegTool.v2.exe "${NSISDIR}\Bin\RegTool.bin"

be

File /oname=$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin"

to go with the WriteRegStr defining RunOnce ?

The diff shows other changes (get library version) etc. I assume they are for other things.


Thanks, fixed.

The library version changes require the latest LibraryLocal.exe as well. You can revert those changes until 2.11 if you don't want to get the latest CVS version.



Originally posted by bg123
Can't delete a running executable. The best solution would be a way for a process to tell windows "wait until I exit, then delete me". yes it is possible, its a bit of a hack but it IS possible

http://www.catch22.net/tuts/selfdel.asp
http://www.nsonic.de/Delphi/txt_WIS00561.htm