![]() |
Platforms, Frameworks & Libraries »
Vista API »
General
Intermediate
How to Develop Restart Manager Aware Application: Test Case 30By Jatin PrajapatiHere I am showing how to Implement Windows Vista’s Restart Manager |
VB 8.0.NET 2.0, VistaVS2005, Dev
|
||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
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.
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
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
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
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.
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 Aug 2007 Editor: |
Copyright 2007 by Jatin Prajapati Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |