Click here to Skip to main content
15,886,059 members
Articles / Programming Languages / Visual Basic
Article

How to Develop Restart Manager Aware Application: Test Case 30

Rate me:
Please Sign up or sign in to vote.
3.17/5 (7 votes)
14 Aug 20073 min read 62.2K   412   14   10
Here I am showing how to Implement Windows Vista’s Restart Manager

Introduction

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

Background

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
      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
RM_UNIQUE_PROCESS
structures, to a Restart Manager session.

4. RMRestart

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

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:

http://msdn2.microsoft.com/en-us/library/aa373649.aspx

  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.
"RegisterApplicationRestart"

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:

http://msdn2.microsoft.com/EN-US/library/aa373347.aspx

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
WM_QUERYENDSESSION0x001117
ENDSESSION_CLOSEAPP0x11

Here is code to listen WM Messages

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

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

         MyBase.WndProc(msg) 
         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.)

Conclusion

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

Useful Links:

http://channel9.msdn.com/Showpost.aspx?postid=251492
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.wndproc.aspx

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

License

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


Written By
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 Asp.net, Vb.net,C#.Net, Crystal Reports,GDI+, Ajax, WCF, Silverlight SQL Server,IIS Admin,TFA ,Application Architecture Designing.

Comments and Discussions

 
QuestionDownload rmtool Pin
Member 45038479-Nov-16 18:59
Member 45038479-Nov-16 18:59 
GeneralRestart resistent programs Pin
madankumarrajan11-Nov-09 0:56
madankumarrajan11-Nov-09 0:56 
QuestionWhat for programs without Window? Pin
muttbaha9-Jul-09 22:26
muttbaha9-Jul-09 22:26 
AnswerRe: What for programs without Window? Pin
muttbaha9-Jul-09 23:33
muttbaha9-Jul-09 23:33 
AnswerRe: What for programs without Window? Pin
Msftone20-Aug-09 19:13
Msftone20-Aug-09 19:13 
QuestionCan I install the restart manager to work in XP? Pin
gravz8426-Nov-07 2:42
gravz8426-Nov-07 2:42 
AnswerRe: Can I install the restart manager to work in XP? Pin
Jatin Prajapati29-Nov-07 2:40
Jatin Prajapati29-Nov-07 2:40 
GeneralRe: Can I install the restart manager to work in XP? Pin
gravz8429-Nov-07 3:15
gravz8429-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.