Old 1st March 2018, 20:08   #1
TrifonovS
Senior Member
 
Join Date: Apr 2009
Location: Bulgaria
Posts: 149
Execute actions before reboot

Hi,
I have a strange issue and I cannot find a solution. My installer calls an external installer (included in it), but sometimes this external installer reboots the PC. I want my installer to execute some actions before the reboot. How it can handle this?
TrifonovS is offline   Reply With Quote
Old 2nd March 2018, 22:45   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,768
I don't see how you can, ExecWait does not return until the process has completed. Is this a MSI based external installer?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th March 2018, 20:13   #3
TrifonovS
Senior Member
 
Join Date: Apr 2009
Location: Bulgaria
Posts: 149
Yes, it is MSI based installer. I know that I cannot do anything inside my installer, but I'm thinking that I can register somewhere another small application (before to call this external installer) that will be called when Windows tries to reboot and it can do the job.But I don't really know how to do it...
TrifonovS is offline   Reply With Quote
Old 4th March 2018, 21:39   #4
Nutzzz
Junior Member
 
Join Date: May 2007
Location: Orange County, CA, U.S.A.
Posts: 45
MSI installers take the /norestart command line parameter, and return 3010 if install was successful but requires a reboot.

If the installer didn't take a command line parameter, I could think of some wacky hacks like adding a logoff script and then removing it once the script runs, or just removing it without running it if the installer didn't reboot.
Nutzzz is offline   Reply With Quote
Old 5th March 2018, 11:06   #5
TrifonovS
Senior Member
 
Join Date: Apr 2009
Location: Bulgaria
Posts: 149
Thank you Nutzzz, but ca you explain a little bit the idea of the logoff script. I didn't get it...
TrifonovS is offline   Reply With Quote
Old 5th March 2018, 18:52   #6
Nutzzz
Junior Member
 
Join Date: May 2007
Location: Orange County, CA, U.S.A.
Posts: 45
Well, since the former method should work for you, that's by far the better solution.

The hacky method I mention is to replicate the method that the group policy editor uses to assign a shutdown script to the machine (or a logoff script for the current user) by using a .reg file with "regedit.exe /s regfile.reg" (and/or a group of WriteRegStr/WriteRegDWORD NSIS commands). See this page for an example .reg file for a startup script.

Your script would be a .bat/.cmd or .vbs file that runs your actions and then applies another .reg file that deletes the registry entries so the shutdown script doesn't run next time around. If you want/need to use NSIS for your actions, you could create another installer or even leverage your uninstaller by calling it with a command line parameter that uses an otherwise unused routine and then immediately quits before the regular uninstall routines begin.

If a reboot isn't performed and execution returns to your installer, then delete the registry entries so that they're never used.

FYI, to delete registry values using a .reg file, assign it an unquoted hyphen (-), e.g.:
code:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0]
"Script"=-
"Parameters"=-
"ExecTime"=-

Nutzzz is offline   Reply With Quote
Old 5th March 2018, 19:12   #7
TrifonovS
Senior Member
 
Join Date: Apr 2009
Location: Bulgaria
Posts: 149
Hi again Nutzzz,
Thanks a lot. This is exactly what I'm searching for.
TrifonovS is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

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