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
- What is Restart Manager?
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.
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.
- Why we need Restart Manager in our application?
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.
- Brief Introduction about Restart Manager API
- 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
- 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 | Hexadecimal | Decimal |
WM_QUERYENDSESSION | 0x0011 | 17 |
ENDSESSION_CLOSEAPP | 0x1 | 1 |
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
- How we can say, My Application is Restart Manager Aware?
- To check application is support Restart manager or not. You need rmtool.exe.
- 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.