Continue After Reboot of System

Hello,

I have been looking extensively online but am unable to find any reliable information. I created a installer program for work that will install programs, drivers, windows updates, and modify the registry for certain IE and Windows Settings. Everything works great but the problem is at certain times the system needs to be rebooted otherwise the remaining installs get rolled back because there is a pending reboot needed. How do I get my program to reboot the system and continue where it left off after reboot? Again, I don't seem to be able to find any good information at all. Any help would be appreciated! I have a snippet of code for after the windows updates in case that helps for any coding purposes.

Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 /*  If ID_WU Is Selected Install */                                                                   
                         checked = IsDlgButtonChecked(hwnd, ID_WU);  
                          if (checked){
                           	   
                           	   	  CreateProcess(TEXT("E:\\Programs\\WindowsUpdates\\WU.bat"),
												 NULL,NULL,NULL,FALSE,
												 CREATE_NEW_CONSOLE,
												 NULL,NULL,&si,&pi);
						  WaitForSingleObject( pi.hProcess, INFINITE );																									  													       
						  }
						          /*  When program completes notify tech  */
						          CreateProcess(TEXT("E:\\Programs\\completion.bat"),
												 NULL,NULL,NULL,FALSE,
												 CREATE_NEW_CONSOLE,
												 NULL,NULL,&si,&pi);
						  WaitForSingleObject( pi.hProcess, INFINITE );	
It's going to be on the lines of this:

1. Begin installation
2. Save installation data to a file
3. Add your program to the registry, adding a -finish on the command line
( HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce )
4. Reboot
5. Your program will start again, but with a -finish on the command line.
Detect it and finish installation.
Great information, I do have a few questions though. With regards to saving installation data to a file, how would I go about doing that? Would the program being added to the registry occur following a program install that requires a reboot? So include a call to a batch file that runs the registry key that you provided? I appreciate the information, I have been searching for days for something realiable.
SGH's post is probably the most straightforward and correct way to do this. I was going to post about using a Windows Service to accomplish the same thing but that is going to be more work. I would just like to add to his idea that this will resume your application right around the time that the splash screen for signing into Windows displays, and by default Windows initializes hardware asynchronously on start up. So if you are doing something like applying more updates or pulling files from a remote source then write that part with the expectation that the system has not yet acquired an IP lease. Maybe use something like "IcmpSendEcho()" until it returns with a valid reply?
Last edited on
Ok that is a good bit of information, thanks Computergeek01. I am still not tracking the save installation data to a file, any insights? Is this in reference to the actual .exe that I created?
I would just save some number to a local text file that indicates what stage you are at. So say you are rebooting the first time, that text file should contain a number '1'. Then when the process starts, it reads the text file and it knows what stage to jump to.

Also, I read your comment to SGH, is that all this "program" does is call batch files?

No it only does that when dealing with .exe's and modifying the registry. When using MSI's it uses the msiexec command. I am not sure how I would have the program know which stage to point too. Do you have a really simple way of showing me in the code and text? I'm sorry I am not very good with some of this stuff lol
this program does a possible 60 different things, It installs whatever programs are selected, installs windows updates, modifies IE settings for zone settings, turns off UAC, enables run command on start menu, installs the drivers for whatever system is being imaged. So at certain points the system needs to be restarted in order to continue, I am just having a hard time putting this all together for the reboot portion of it.
You can call executables and pass them command line options with "CreateProcess()" as well and the WinAPI allows you to work with the registry. I'm actually writing something right now that does the later.

But anyway, you are probably over thinking this. You know what steps cause a reboot right? Just before you execute those steps write a number out into this file. A simple std::ofstream is all you need. Then every time you program starts up have it look for that file. If it doesn't exist then you know that it knows to start from the beginning, if you see a number '1' then it knows start after the first reboot, a number '2' would indicate the second reboot etc.

EDIT: You should be installing drivers through the sysprep.ini file on the image. Why would you bother with a custom solution for that part? For that matter, updates should be done through WSUS and things like IE settings, UAC and autoruns etc. should be done with GPO's... What aren't you using Active Directory for this stuff OP?

EDIT 2: Come in here for a minute - http://webchat.quakenet.org/?channels=#cplusplus
Last edited on
Im in the chat
Registered users can post here. Sign in or register to post.