Windows Restart Manager Restart Manager

Source: Internet
Author: User

Restart Manager (RM) can reduce or avoid the number of system restarts required to install or update the program. The main reason to restart during installation (or update) is that some files that need to be updated are currently being used by some other program or service. RM allows all programs (or services) except critical system Services (Critical system service) to be shut down and restarted. This frees the files that are in use so that the installation can be completed.

The  RM DLL exports a set of C interfaces that can be used by the installation package. The installation package can register a list of files that need to be replaced during installation to RM, which can then be used by RM to determine which files are in use, and RM can close and restart the programs that occupy those files; the installation package can be based on the occupied files, process IDs, or the short name of the Windows service to instruct RM to shut down and restart the application (or service).  RM is available from Vista, Windows Installer V4 automatically uses RM, custom Installer can also call the RM API to use its features. In the case of unavoidable reboots, installer can use RM to plan when to restart to minimize interference with user workflows.   for programs that occupy files, RM closes them in the following order, and restarts them in reverse order after the update is complete: 1. GUI application 2. Console Application 3. Windows Services 4. Windows EXPLORER RM Closes the program (or service) only if it is allowed by the caller. Closing operations across sessions is not supported.   for an installation package that uses Windows Installer V4, its user interface should include the Msirmfilesinuse dialog box if it is interactive.  1. Using the RM API in a custom installation package all operations performed through the RM API must be associated with a session. In a user session, up to 64 RM sessions can be opened at the same time. The main installation package (Primary Installer) is responsible for starting and stopping the RM session.   If necessary, several from the installation package (secondary Installer) can join the RM session and run concurrently with the main installation package (in the same process or in different processes). You need to use the session key to join the RM session.   The user interface of the interactive installation package should include a msirmfilesinuse dialog box--used to request that the user close the application or service. The   installation package cannot disable file system redirection before calling the RM API, which means that a 32-bit installation package running on 64-bit Windows cannot register files in the "%windir\system32" directory.  1.1 using RM in the main installation package when using RM in a single installation package, the installation package is the main installation package. 1. Call Rmstartsession to start an RM session and get session handle and key. 2. Call Rmregisterresources registered resources. RM can only use registered resources to determine which programs and services need to be restarted. A resource can be a file name, a short name for a service, or a rm_unique_process structure. 3. Call Rmgetlist to get an array of rm_process_info that contains all the processes and services that need to be restarted.     If Rmgetlist returns a Lpdwrebootreason that is not 0, RM cannot restart to release the registered resource. In this case, you will need to restart the OS to complete the installation.if Rmgetlist returns a Lpdwrebootreason of 0, you can close the resource-consuming programs and services by calling Rmshutdown, and then the installation package can perform the installation operation, and finally, call Rmrestart to restart the closed program. 4. Rmaddfilter can be used to prevent certain programs (or services) from being closed by RM, which is called adding a filter. Rmremovefilter can remove a filter, rmgetfilterlist can get the current filter list. 5. Call Rmendsession to close the RM session. Example:DWORD dval = 0;DWORD Dwsessionhandle = (DWORD)-1;WCHAR sesskey[cch_rm_session_key+1];UINT nprocinfo = +;UINT nprocinfoneeded;UINT naffectedapps = 0;Rm_process_info rgaffectedapps[100];//size depends on # of entries found by RmgetlistDWORD lpdwrebootreason = 0;DWORD nservices = 1;LPCWSTR rgsservices[] = {L "IISAdmin"};DWORD nprocs = 0;DWORD nfiles = 1;LPCWSTR rgsfiles[] = {L "C:\\windows\\system32\\oleaut32.dll"};//Starting Sessiondval = rmstartsession (&dwsessionhandle, 0, Sesskey);if (dval! = ERROR_SUCCESS)goto Rm_end; //Register Itemsdval = rmregisterresources (Dwsessionhandle,nfiles, Rgsfiles, //Files Nprocs, NULL, //Processes nservices, rgsservices); //Services if (dval! = ERROR_SUCCESS)goto Rm_end;//Getting affected appsdval = rmgetlist (Dwsessionhandle,&nprocinfoneeded,&naffectedapps, Rgaffectedapps, &lpdwrebootreason);if (dval! = ERROR_SUCCESS)goto Rm_end;//results of Rmgetlist can be presented & interpreted//by the user for determining subsequent action.//Shut down appsdval = Rmshutdown (dwsessionhandle, 0, NULL);if (dval! = ERROR_SUCCESS)goto Rm_end;//an Installer can now replace the files.//Restart appsdval = Rmrestart (dwsessionhandle, 0, NULL);if (dval! = ERROR_SUCCESS)goto Rm_end;Rm_end:if (Rgaffectedapps) {Delete [] Rgaffectedapps;Rgaffectedapps = NULL; }if (dwsessionhandle! =-1) {// Clean up sessiondval = rmendsession (dwsessionhandle);dwsessionhandle =-1;}  1.2 is using RM1 from the installation package. Find a way to get RM session key from the main installation package and call Rmjoinsession to join the session. The master installation package and the from installation package must run in the same user context. 2. Use Rmregisterresources to register resources, use Rmgetlist to get a list of the programs that occupy the resources, 3. Can call Rmshutdown (doubt!) If it can be called, will it be possible to call Rmshutdown multiple times? )。 4. Master install package and call Rmendsession from the installation package (in doubt, it means that either party calls or both sides need to call once).   Example:     DWORD Dval = 0;    DWORD Dwsessionhandle = (DWORD) -1;    Wcha R sesskey[cch_rm_session_key+1]; Primary Installer Session key.    DWORD nservices = 1;    lpcwstr rgsservices[] = {L ' Iisa DMin "};    DWORD Nprocs = 0;    DWORD nfiles = 1;    LPCWSTR rgsFiles[] = { L "C:\\windows\\system32\\oleaut32.dll"}; //Secondary installer obtains the session key from the//primary Installe R & uses it to join the session.    //joining session    dval = Rmjoinsession (&A Mp;dwsessionhandle, Sesskey);    if (dval! = ERROR_SUCCESS)         goto rmsub_end;    //Register items. The secondary installer is a allowed to register resources   //and cannot perform other Restart Manage R operations.    dval = rmregisterresources (        dwsessionhandle,        Nfiles, rgsfiles,            //files        Nprocs, null,            //processes        nservices , rgsservices);       //services     if (dVal! = ERROR_ SUCCESS)         Goto rmsub_end; rmsub_end:    if ( Dwsessionhandle! =-1)     {       //Clean up session  & nbsp;     dval = rmendsession (dwsessionhandle);        dwSessionHandle = -1; & nbsp; }   from: Ms-help://ms. msdnqtr.v90.chs/rstmgr/rstmgr/using_restart_manager.htm           
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.