winapi_ui_automation/um/
restartmanager.rs

1// Licensed under the Apache License, Version 2.0
2// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4// All files in the project carrying such notice may not be copied, modified, or distributed
5// except according to those terms.
6//! RestartManager include file
7use shared::minwindef::{BOOL, DWORD, FILETIME, LPDWORD, PBYTE, UINT, ULONG};
8use um::winnt::{LPCWSTR, LPWSTR, WCHAR};
9pub const RM_SESSION_KEY_LEN: usize = 16; // mem::size_of::<GUID>()
10pub const CCH_RM_SESSION_KEY: usize = RM_SESSION_KEY_LEN * 2;
11pub const CCH_RM_MAX_APP_NAME: usize = 255;
12pub const CCH_RM_MAX_SVC_NAME: usize = 63;
13pub const RM_INVALID_TS_SESSION: DWORD = -1i32 as u32;
14pub const RM_INVALID_PROCESS: DWORD = -1i32 as u32;
15ENUM!{enum RM_APP_TYPE {
16    RmUnknownApp = 0,
17    RmMainWindow = 1,
18    RmOtherWindow = 2,
19    RmService = 3,
20    RmExplorer = 4,
21    RmConsole = 5,
22    RmCritical = 1000,
23}}
24ENUM!{enum RM_SHUTDOWN_TYPE {
25    RmForceShutdown = 0x1,
26    RmShutdownOnlyRegistered = 0x10,
27}}
28ENUM!{enum RM_APP_STATUS {
29    RmStatusUnknown = 0x0,
30    RmStatusRunning = 0x1,
31    RmStatusStopped = 0x2,
32    RmStatusStoppedOther = 0x4,
33    RmStatusRestarted = 0x8,
34    RmStatusErrorOnStop = 0x10,
35    RmStatusErrorOnRestart = 0x20,
36    RmStatusShutdownMasked = 0x40,
37    RmStatusRestartMasked = 0x80,
38}}
39ENUM!{enum RM_REBOOT_REASON {
40    RmRebootReasonNone = 0x0,
41    RmRebootReasonPermissionDenied = 0x1,
42    RmRebootReasonSessionMismatch = 0x2,
43    RmRebootReasonCriticalProcess = 0x4,
44    RmRebootReasonCriticalService = 0x8,
45    RmRebootReasonDetectedSelf = 0x10,
46}}
47STRUCT!{struct RM_UNIQUE_PROCESS {
48    dwProcessId: DWORD,
49    ProcessStartTime: FILETIME,
50}}
51pub type PRM_UNIQUE_PROCESS = *mut RM_UNIQUE_PROCESS;
52STRUCT!{struct RM_PROCESS_INFO {
53    Process: RM_UNIQUE_PROCESS,
54    strAppName: [WCHAR; CCH_RM_MAX_APP_NAME + 1],
55    strServiceShortName: [WCHAR; CCH_RM_MAX_SVC_NAME + 1],
56    ApplicationType: RM_APP_TYPE,
57    AppStatus: ULONG,
58    TSSessionId: DWORD,
59    bRestartable: BOOL,
60}}
61pub type PRM_PROCESS_INFO = *mut RM_PROCESS_INFO;
62ENUM!{enum RM_FILTER_TRIGGER {
63    RmFilterTriggerInvalid = 0,
64    RmFilterTriggerFile,
65    RmFilterTriggerProcess,
66    RmFilterTriggerService,
67}}
68ENUM!{enum RM_FILTER_ACTION {
69    RmInvalidFilterAction = 0,
70    RmNoRestart = 1,
71    RmNoShutdown = 2,
72}}
73UNION!{union RM_FILTER_INFO_u {
74    [u32; 3] [u64; 2],
75    strFilename strFilename_mut: LPWSTR,
76    Process Process_mut: RM_UNIQUE_PROCESS,
77    strServiceShortName strServiceShortName_mut: LPWSTR,
78}}
79STRUCT!{struct RM_FILTER_INFO {
80    FilterAction: RM_FILTER_ACTION,
81    FilterTrigger: RM_FILTER_TRIGGER,
82    cbNextOffset: DWORD,
83    u: RM_FILTER_INFO_u,
84}}
85pub type PRM_FILTER_INFO = *mut RM_FILTER_INFO;
86FN!{cdecl RM_WRITE_STATUS_CALLBACK(
87    nPercentComplete: u32,
88) -> ()}
89extern "system" {
90    pub fn RmStartSession(
91        pSessionHandle: *mut DWORD,
92        dwSessionFlags: DWORD,
93        strSessionKey: *mut WCHAR,
94    ) -> DWORD;
95    pub fn RmJoinSession(
96        pSessionHandle: *mut DWORD,
97        strSessionKey: *const WCHAR,
98    ) -> DWORD;
99    pub fn RmEndSession(
100        dwSessionHandle: DWORD,
101    ) -> DWORD;
102    pub fn RmRegisterResources(
103        dwSessionHandle: DWORD,
104        nFiles: UINT,
105        rgsFileNames: *mut LPCWSTR,
106        nApplications: UINT,
107        rgApplications: *mut RM_UNIQUE_PROCESS,
108        nServices: UINT,
109        rgsServiceNames: *mut LPCWSTR,
110    ) -> DWORD;
111    pub fn RmGetList(
112        dwSessionHandle: DWORD,
113        pnProcInfoNeeded: *mut UINT,
114        pnProcInfo: *mut UINT,
115        rgAffectedApps: *mut RM_PROCESS_INFO,
116        lpdwRebootReasons: LPDWORD,
117    ) -> DWORD;
118    pub fn RmShutdown(
119        dwSessionHandle: DWORD,
120        lActionFlags: ULONG,
121        fnStatus: RM_WRITE_STATUS_CALLBACK,
122    ) -> DWORD;
123    pub fn RmRestart(
124        dwSessionHandle: DWORD,
125        dwRestartFlags: DWORD,
126        fnStatus: RM_WRITE_STATUS_CALLBACK,
127    ) -> DWORD;
128    pub fn RmCancelCurrentTask(
129        dwSessionHandle: DWORD,
130    ) -> DWORD;
131    pub fn RmAddFilter(
132        dwSessionHandle: DWORD,
133        strModuleName: LPCWSTR,
134        pProcess: *mut RM_UNIQUE_PROCESS,
135        strServiceShortName: LPCWSTR,
136        FilterAction: RM_FILTER_ACTION,
137    ) -> DWORD;
138    pub fn RmRemoveFilter(
139        dwSessionHandle: DWORD,
140        strModuleName: LPCWSTR,
141        pProcess: *mut RM_UNIQUE_PROCESS,
142        strServiceShortName: LPCWSTR,
143    ) -> DWORD;
144    pub fn RmGetFilterList(
145        dwSessionHandle: DWORD,
146        pbFilterBuf: PBYTE,
147        cbFilterBuf: DWORD,
148        cbFilterBufNeeded: LPDWORD,
149    ) -> DWORD;
150}