ReactOS 0.4.15-dev-5865-g640e228
shutdown.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/advapi32/misc/shutdown.c
5 * PURPOSE: System shutdown functions
6 * PROGRAMMER: Lee Schroeder <spaceseel at gmail dot com>
7 * Emanuele Aliberti
8 */
9
10#include <advapi32.h>
11
13
14/**********************************************************************
15 * AbortSystemShutdownA
16 *
17 * see AbortSystemShutdownW
18 */
21{
22 ANSI_STRING MachineNameA;
23 UNICODE_STRING MachineNameW;
25 BOOL rv;
26
27 RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName);
28 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
30 {
32 return FALSE;
33 }
34
35 rv = AbortSystemShutdownW(MachineNameW.Buffer);
36 RtlFreeUnicodeString(&MachineNameW);
38 return rv;
39}
40
41
42/**********************************************************************
43 * AbortSystemShutdownW
44 *
45 * @implemented
46 */
49{
50 DWORD dwError;
51
53 {
54 dwError = BaseAbortSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName);
55 }
57 {
59 }
61
62 if (dwError != ERROR_SUCCESS)
63 {
64 TRACE("BaseAbortSystemShutdown() failed (Error %lu)\n", dwError);
65 SetLastError(dwError);
66 return FALSE;
67 }
68
69 return TRUE;
70}
71
72
73/**********************************************************************
74 * InitiateSystemShutdownA
75 *
76 * @implemented
77 */
78BOOL
81 LPSTR lpMessage,
83 BOOL bForceAppsClosed,
84 BOOL bRebootAfterShutdown)
85{
86 ANSI_STRING MachineNameA, MessageA;
87 UNICODE_STRING MachineNameW, MessageW;
89 BOOL res;
90
91 MachineNameW.Buffer = NULL;
92 MessageW.Buffer = NULL;
93
94 if (lpMachineName)
95 {
96 RtlInitAnsiString(&MachineNameA, lpMachineName);
97 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
99 {
100 if(MachineNameW.Buffer)
101 RtlFreeUnicodeString(&MachineNameW);
102
104 return FALSE;
105 }
106 }
107
108 if (lpMessage)
109 {
110 RtlInitAnsiString(&MessageA, lpMessage);
111 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
112 if (STATUS_SUCCESS != Status)
113 {
114 if (MessageW.Buffer)
115 RtlFreeUnicodeString(&MessageW);
116
118 return FALSE;
119 }
120 }
121
122 res = InitiateSystemShutdownW(MachineNameW.Buffer,
123 MessageW.Buffer,
124 dwTimeout,
125 bForceAppsClosed,
126 bRebootAfterShutdown);
127
128 /* Clear the values of both strings */
129 if (lpMachineName)
130 RtlFreeUnicodeString(&MachineNameW);
131
132 if (lpMessage)
133 RtlFreeUnicodeString(&MessageW);
134
135 return res;
136}
137
138
139/**********************************************************************
140 * InitiateSystemShutdownW
141 *
142 * @implemented
143 */
146 LPWSTR lpMessage,
148 BOOL bForceAppsClosed,
149 BOOL bRebootAfterShutdown)
150{
152 DWORD dwError;
153
154 RtlInitUnicodeString(&Message, lpMessage);
155
157 {
158 dwError = BaseInitiateSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName,
160 dwTimeout,
161 bForceAppsClosed,
162 bRebootAfterShutdown);
163 }
165 {
167 }
169
170 if (dwError != ERROR_SUCCESS)
171 {
172 TRACE("BaseInitiateSystemShutdown() failed (Error %lu)\n", dwError);
173 SetLastError(dwError);
174 return FALSE;
175 }
176
177 return TRUE;
178}
179
180
181/******************************************************************************
182 * InitiateSystemShutdownExA [ADVAPI32.@]
183 *
184 * see InitiateSystemShutdownExW
185 */
188 LPSTR lpMessage,
190 BOOL bForceAppsClosed,
191 BOOL bRebootAfterShutdown,
193{
194 ANSI_STRING MachineNameA, MessageA;
195 UNICODE_STRING MachineNameW, MessageW;
197 BOOL res;
198
199 MachineNameW.Buffer = NULL;
200 MessageW.Buffer = NULL;
201
202 if (lpMachineName)
203 {
204 RtlInitAnsiString(&MachineNameA, lpMachineName);
205 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
206 if (STATUS_SUCCESS != Status)
207 {
208 if(MachineNameW.Buffer)
209 RtlFreeUnicodeString(&MachineNameW);
210
212 return FALSE;
213 }
214 }
215
216 if (lpMessage)
217 {
218 RtlInitAnsiString(&MessageA, lpMessage);
219 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
220 if (STATUS_SUCCESS != Status)
221 {
222 if (MessageW.Buffer)
223 RtlFreeUnicodeString(&MessageW);
224
226 return FALSE;
227 }
228 }
229
230 res = InitiateSystemShutdownExW(MachineNameW.Buffer,
231 MessageW.Buffer,
232 dwTimeout,
233 bForceAppsClosed,
234 bRebootAfterShutdown,
235 dwReason);
236
237 /* Clear the values of both strings */
238 if (lpMachineName)
239 RtlFreeUnicodeString(&MachineNameW);
240
241 if (lpMessage)
242 RtlFreeUnicodeString(&MessageW);
243
244 return res;
245}
246
247
248/******************************************************************************
249 * InitiateSystemShutdownExW [ADVAPI32.@]
250 *
251 * @unimplemented
252 */
255 LPWSTR lpMessage,
257 BOOL bForceAppsClosed,
258 BOOL bRebootAfterShutdown,
260{
262 DWORD dwError;
263
264 RtlInitUnicodeString(&Message, lpMessage);
265
267 {
270 dwTimeout,
271 bForceAppsClosed,
272 bRebootAfterShutdown,
273 dwReason);
274 }
276 {
277 dwError = RpcExceptionCode();
278 }
280
281 if (dwError != ERROR_SUCCESS)
282 {
283 TRACE("BaseInitiateSystemShutdownEx() failed (Error %lu)\n", dwError);
284 SetLastError(dwError);
285 return FALSE;
286 }
287
288 return TRUE;
289}
290
291
292/******************************************************************************
293 * InitiateShutdownW [ADVAPI32.@]
294 *
295 * @unimplemented
296 */
299 LPWSTR lpMessage,
300 DWORD dwGracePeriod,
301 DWORD dwShutdownFlags,
303{
305 return ERROR_SUCCESS;
306}
307
308/******************************************************************************
309 * InitiateShutdownA [ADVAPI32.@]
310 *
311 * see InitiateShutdownW
312 */
315 LPSTR lpMessage,
316 DWORD dwGracePeriod,
317 DWORD dwShutdownFlags,
319{
320 ANSI_STRING MachineNameA, MessageA;
321 UNICODE_STRING MachineNameW, MessageW;
323 INT LastError;
324 DWORD rv;
325
326 MachineNameW.Buffer = NULL;
327 MessageW.Buffer = NULL;
328
329 if (lpMachineName)
330 {
331 RtlInitAnsiString(&MachineNameA, lpMachineName);
332 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
333 if (STATUS_SUCCESS != Status)
334 {
335 if(MachineNameW.Buffer)
336 RtlFreeUnicodeString(&MachineNameW);
337
339 return FALSE;
340 }
341 }
342
343 if (lpMessage)
344 {
345 RtlInitAnsiString(&MessageA, lpMessage);
346 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
347 if (STATUS_SUCCESS != Status)
348 {
349 if (MessageW.Buffer)
350 RtlFreeUnicodeString(&MessageW);
351
353 return FALSE;
354 }
355 }
356
357 rv = InitiateShutdownW(MachineNameW.Buffer,
358 MessageW.Buffer,
359 dwGracePeriod,
360 dwShutdownFlags,
361 dwReason);
362 LastError = GetLastError();
363
364 /* Clear the values of both strings */
365 if (lpMachineName)
366 RtlFreeUnicodeString(&MachineNameW);
367
368 if (lpMessage)
369 RtlFreeUnicodeString(&MessageW);
370
371 SetLastError(LastError);
372 return rv;
373}
374
375/* EOF */
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
DWORD dwReason
Definition: misc.cpp:154
ULONG __stdcall BaseInitiateSystemShutdown(PREGISTRY_SERVER_NAME ServerName, PRPC_UNICODE_STRING lpMessage, ULONG dwTimeout, BOOLEAN bForceAppsClosed, BOOLEAN bRebootAfterShutdown)
Definition: rpcserver.c:409
ULONG __stdcall BaseAbortSystemShutdown(PREGISTRY_SERVER_NAME ServerName)
Definition: rpcserver.c:429
ULONG __stdcall BaseInitiateSystemShutdownEx(PREGISTRY_SERVER_NAME ServerName, PRPC_UNICODE_STRING lpMessage, ULONG dwTimeout, BOOLEAN bForceAppsClosed, BOOLEAN bRebootAfterShutdown, ULONG dwReason)
Definition: rpcserver.c:494
#define UNIMPLEMENTED
Definition: debug.h:115
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI AbortSystemShutdownA(LPCSTR lpMachineName)
Definition: shutdown.c:20
BOOL WINAPI AbortSystemShutdownW(LPCWSTR lpMachineName)
Definition: shutdown.c:48
BOOL WINAPI InitiateSystemShutdownExA(LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown, DWORD dwReason)
Definition: shutdown.c:187
BOOL WINAPI InitiateSystemShutdownA(LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown)
Definition: shutdown.c:80
DWORD WINAPI InitiateShutdownA(LPSTR lpMachineName, LPSTR lpMessage, DWORD dwGracePeriod, DWORD dwShutdownFlags, DWORD dwReason)
Definition: shutdown.c:314
BOOL WINAPI InitiateSystemShutdownW(LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown)
Definition: shutdown.c:145
DWORD WINAPI InitiateShutdownW(LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwGracePeriod, DWORD dwShutdownFlags, DWORD dwReason)
Definition: shutdown.c:298
BOOL WINAPI InitiateSystemShutdownExW(LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown, DWORD dwReason)
Definition: shutdown.c:254
#define SetLastError(x)
Definition: compat.h:752
static const WCHAR Message[]
Definition: register.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
GLuint res
Definition: glext.h:9613
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define RpcEndExcept
Definition: rpc.h:128
#define RpcTryExcept
Definition: rpc.h:126
#define RpcExcept(expr)
Definition: rpc.h:127
#define RpcExceptionCode()
Definition: rpc.h:132
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
int32_t INT
Definition: typedefs.h:58
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD dwTimeout
Definition: wincrypt.h:6081
#define WINAPI
Definition: msvc.h:6
PWCHAR PREGISTRY_SERVER_NAME
Definition: winreg.idl:10
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185