Click here to Skip to main content
12,887,625 members (31,407 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 14 Aug 2007

How to Develop Restart Manager Aware Application: Test Case 30

, 14 Aug 2007
Rate this:
Please Sign up or sign in to vote.
Here I am showing how to Implement Windows Vista’s Restart Manager


Microsoft has Introduced some nice features in Windows Vista like Restart Manager, Window
Error Reporting, File / Folder and Registry Virtualization.


In this Article I am explaining Details about Restart Manager.Also main purpose to write this
article is to target the Test Case 30. So it will help to those developers who are going to
Participate Windows Vista Logo Certification Process. This article will help them to solve Test Cases 30

First let me Introduce about Restart Manager.

Restart Manager

  1. What is Restart Manager?
    1. When we install any software or updating Existing Software, at that time some
      software requires to restart system during installation process. So system get
      restarted and again start user has to open all running application again, and this
      is very odd things for end users.
    2. Now to overcome this situation, Windows Vista's Restart Manager will Maintain
      the State of application and Shutdown and again Restart according to
      application Settings.
  1. Why we need Restart Manager in our application?
    1. To Run application Properly into Windows Vista, Developers must have to
      Develop RM Aware application. Because Microsoft has Started the Windows <place w:st="on" />Vista</place />
      Logo Certification Program to Make application Reliable, and Compatible with
      Windows Vista.
  1. Brief Introduction about Restart Manager API
    1. Restart Manager API.

i. rstrtmgr.dll is used for RM

ii. List of RM API

1. RMStartSession

a. Starts a new Restart Manager session.

2. RMGetList

a. Used by installers to get a list of all applications affected by registered
resources and their current status.

3. RMRegisterResources

a. Registers resources, such as filenames, service short names, or
structures, to a Restart Manager session.

4. RMRestart

a. Restarts applications and services that have been shut down by the
function and that have been registered for restart using

5. RMShutDown

a. Initiates the shut down of applications and services.

6. RMEndSession

a. Ends the Restart Manager session.

API Implementation using VB.Net

Here I am Writing Sample Code for Some API

<DllImport("rstrtmgr.dll", CharSet:=CharSet.Auto)> _ 
Friend Shared Function RmStartSession(ByRef pSessionHandle As UInteger, _
 ByVal dwSessionFlags As Integer, ByVal strSessionKey As StringBuilder) As Integer 
End Function 

<DllImport("rstrtmgr.dll", CharSet:=CharSet.Auto)> _ 
Friend Shared Function RmRegisterResources(ByVal pSessionHandle As UInteger, _
 ByVal nFiles As Integer, ByVal rgsFilenames As String(), ByVal nApplications As Integer,_
 ByVal rgApplications As RM_UNIQUE_PROCESS(), ByVal nServices As Integer,_

 ByVal rgsServiceNames As String()) As Integer 

End Function                               

<DllImport("rstrtmgr.dll", CharSet:=CharSet.Auto)> _ 
Friend Shared Function RmShutdown(ByVal pSessionHandle As UInteger, _
 ByVal dwSessionFlags As UInteger, ByVal fnStatus As IntPtr) As Integer 
End Function 

<DllImport("rstrtmgr.dll", CharSet:=CharSet.Auto)> _ 
Friend Shared Function RmRestart(ByVal pSessionHandle As UInteger, _
 ByVal dwRestartFlags As UInteger, ByVal fnStatus As IntPtr) As Integer 
End Function 

<DllImport("rstrtmgr.dll", CharSet:=CharSet.Auto)> _ 
Friend Shared Function RmEndSession(ByVal pSessionHandle As UInteger)_
 As Integer 
End Function

To get full details about Restart Manager API. Check following URL:

  1. How to develop Restart Manager Aware Application?

To Implement RM into our application, we have to use kernel32.dll API. We don't need
to implement RM API into application, but just have to implement only one API from
Kernel32.dll to Register our application for Restart Manager.

Here is code to Implement kernel32.dll API

<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _ 
Public Shared Function RegisterApplicationRestart(ByVal pszCommandline_
 As String, ByVal dwFlags As Integer) As UInteger 

End Function

Registers the active instance of an application for restart.

HRESULT WINAPI RegisterApplicationRestart( PCWSTR pwzCommandline, DWORD dwFlags );

Click on below link to get details about this function parameters:

now call this function from application main class or on Form load event.

But Before Register Application for Restart manager, we have to check the Operating System
version, because Windows XP and Previous OS version is not supporting RM API. So may be
it Raise error, when you will try to RegisterApplicationRestart.

To Overcome this problem, you have to just call this function.

Public Function RunningVistaOrLater() As Boolean 
      Return System.Environment.OSVersion.Version.Major > 5 
End Function

Private Sub frmRMAware_Load(ByVal sender As System.Object,_
 ByVal e As System.EventArgs) Handles MyBase.Load
    '======= Check application is Running on Vista OR or Later Version
   If RunningVistaOrLater Then
         '========== RegisterApplication For RM
         RegisterApplicationRestart("Test", 0)
    End If
End Sub

Now in next step, we have to override the WndProc method to listen messages For

Windows Message HexadecimalDecimal

Here is code to listen WM Messages

Private WM_QUERYENDSESSION As Int32 = 17 
Private WM_ENDSESSION As Int32 = 22 

Protected Overloads Overrides Sub WndProc(_
 ByRef msg As System.Windows.Forms.Message) 

         If msg.Msg = WM_QUERYENDSESSION Or msg.Msg = WM_ENDSESSION Then 
            If msg.LParam.ToString = ENDSESSION_CLOSEAPP Then 
                  '; Here Write Code to Save application State, when its 
                   'going to shutdown or restart 
            End If 
         End If 
End Sub
  1. How we can say, My Application is Restart Manager Aware?
    1. To check application is support Restart manager or not. You need rmtool.exe.
    2. Here is command for that

i. rmtool.exe –p dwPID –S –R

1. dwPID= application's Process ID

2. –S = Application to Shutdown

3. –R = Application Restart after Shutdown

To Get all Parameters about RMTOOL just check the help command to get RMTool help

(Note: Please Write Exact command mean –S and –R in Upper case.)


So this way we can implement RM into our application to develop RM aware

Useful Links:

Please Feel free to contact me to solve any Test case for Windows Vista Logo Program.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jatin Prajapati
Team Leader
India India
Jatin is Working in .Net Technology Since 2006. He has Completed Master of Science Degree in Information Technology. He Likes to learn Cutting edge technologies. He has good Skills in,,C#.Net, Crystal Reports,GDI+, Ajax, WCF, Silverlight SQL Server,IIS Admin,TFA ,Application Architecture Designing.

You may also be interested in...


Comments and Discussions

QuestionDownload rmtool Pin
Member 45038479-Nov-16 18:59
memberMember 45038479-Nov-16 18:59 
GeneralRestart resistent programs Pin
madankumarrajan11-Nov-09 0:56
groupmadankumarrajan11-Nov-09 0:56 
QuestionWhat for programs without Window? Pin
muttbaha9-Jul-09 22:26
membermuttbaha9-Jul-09 22:26 
AnswerRe: What for programs without Window? Pin
muttbaha9-Jul-09 23:33
membermuttbaha9-Jul-09 23:33 
AnswerRe: What for programs without Window? Pin
Msftone20-Aug-09 19:13
memberMsftone20-Aug-09 19:13 
QuestionCan I install the restart manager to work in XP? Pin
gravz8426-Nov-07 2:42
membergravz8426-Nov-07 2:42 
AnswerRe: Can I install the restart manager to work in XP? Pin
Jatin Prajapati29-Nov-07 2:40
memberJatin Prajapati29-Nov-07 2:40 
GeneralRe: Can I install the restart manager to work in XP? Pin
gravz8429-Nov-07 3:15
membergravz8429-Nov-07 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 14 Aug 2007
Article Copyright 2007 by Jatin Prajapati
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid