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