Screenshot 1: RMtestX - not Restart Manager aware
Screenshot 2: RMtestX crashes
Screenshot 3: RMtestX is being patched.
// register with Restart Manager RegisterApplicationRestart(L"-rm", 0);
case WM_CREATE: // // some initialisation stuff // // check to see if RM called us if(RMstart()) { RestoreText(GetDlgItem(hWnd, IDC_EDIT1)); MessageBox(hWnd, L"RMtestV was restarted by the Restart Manager", L"RMtestV: Restart Alert", MB_OK|MB_ICONEXCLAMATION); } return 0;
Event ID: 10002 Source: Restart Manager Type: Information Description: Shutting down application or service 'Restart Manager Example: RM Compliant'. Event ID: 10003 Source: Restart Manager Type: Information Description: Restarting application or service 'Restart Manager Example: RM Compliant'.
case WM_QUERYENDSESSION: // no need to do anything special here // but must return "1" if the application is ready to restart return 1;
You can perform some clean up work when handling WM_QUERYENDSESSION, but the application has to respond quickly at this point, so it is better to delay this work until handling WM_ENDSESSION. In particular, it is a bad idea to prompt for user input in response to WM_QUERYENDSESSION. If your application can't restart, say because it is doing work that can't be interrupted, return "0".
Next comes the notification that the session is ending:
case WM_ENDSESSION: if(ENDSESSION_CLOSEAPP & lParam) { SaveText(GetDlgItem(hWnd, IDC_EDIT1)); } return 0;
Screenshot 4: Restart Manager Prompt
Interacting With the Windows Installer As mentioned above, prior to Windows Vista, any attempt to patch files held open by an application would fail. The best you could get was to prompt the user to manually close the application (and re-open it themselves later), or to require a system reboot. Once an application is RM aware, we need to author the MSI package correctly to take advantage of it. The outline of what needs done is as follows: Dialog Table You need to define the MsiRMFilesInUse dialog. This is very similar to the existing FilesInUse dialog, but it allows the user to select an automatic restart of the application using Restart Manager.
MsiRMFilesInUse Related Tables
Once this is in place, the user will see different options when patching while the application is in use:
Screenshot 5: MsiRMFilesInUse dialog
Further Reading The above isn't everything the Restart Manager has to offer. For example, you can call on it to give you a list of processes holding a given file open, then (if the applications are registered), ask for them to be restarted - essentially what the Windows Installer does behind the scenes. Get more information here: Restart Manager Documentation Application Recovery and Restart Documentation Using Windows Installer with Restart Manager Windows Installer Team Discussion on Restart Manager
Richard Macdonald of the Windows Installer team at Microsoft has posted another great blog article in
On the The OEM Ready Program page, OEM’s can download the OEM Ready Program Test Cases for Windows Vista