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>
12 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
14 /**********************************************************************
15 * AbortSystemShutdownA
17 * see AbortSystemShutdownW
20 AbortSystemShutdownA(LPCSTR lpMachineName
)
22 ANSI_STRING MachineNameA
;
23 UNICODE_STRING MachineNameW
;
27 RtlInitAnsiString(&MachineNameA
, (LPSTR
)lpMachineName
);
28 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
29 if (STATUS_SUCCESS
!= Status
)
31 SetLastError(RtlNtStatusToDosError(Status
));
35 rv
= AbortSystemShutdownW(MachineNameW
.Buffer
);
36 RtlFreeUnicodeString(&MachineNameW
);
37 SetLastError(ERROR_SUCCESS
);
42 /**********************************************************************
43 * AbortSystemShutdownW
48 AbortSystemShutdownW(LPCWSTR lpMachineName
)
54 dwError
= BaseAbortSystemShutdown((PREGISTRY_SERVER_NAME
)lpMachineName
);
56 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
58 dwError
= RtlNtStatusToDosError(RpcExceptionCode());
62 if (dwError
!= ERROR_SUCCESS
)
64 TRACE("BaseAbortSystemShutdown() failed (Error %lu)\n", dwError
);
65 SetLastError(dwError
);
73 /**********************************************************************
74 * InitiateSystemShutdownA
80 InitiateSystemShutdownA(LPSTR lpMachineName
,
83 BOOL bForceAppsClosed
,
84 BOOL bRebootAfterShutdown
)
86 ANSI_STRING MachineNameA
, MessageA
;
87 UNICODE_STRING MachineNameW
, MessageW
;
91 MachineNameW
.Buffer
= NULL
;
92 MessageW
.Buffer
= NULL
;
96 RtlInitAnsiString(&MachineNameA
, lpMachineName
);
97 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
98 if (STATUS_SUCCESS
!= Status
)
100 if(MachineNameW
.Buffer
)
101 RtlFreeUnicodeString(&MachineNameW
);
103 SetLastError(RtlNtStatusToDosError(Status
));
110 RtlInitAnsiString(&MessageA
, lpMessage
);
111 Status
= RtlAnsiStringToUnicodeString(&MessageW
, &MessageA
, TRUE
);
112 if (STATUS_SUCCESS
!= Status
)
115 RtlFreeUnicodeString(&MessageW
);
117 SetLastError(RtlNtStatusToDosError(Status
));
122 res
= InitiateSystemShutdownW(MachineNameW
.Buffer
,
126 bRebootAfterShutdown
);
128 /* Clear the values of both strings */
130 RtlFreeUnicodeString(&MachineNameW
);
133 RtlFreeUnicodeString(&MessageW
);
139 /**********************************************************************
140 * InitiateSystemShutdownW
145 InitiateSystemShutdownW(LPWSTR lpMachineName
,
148 BOOL bForceAppsClosed
,
149 BOOL bRebootAfterShutdown
)
151 UNICODE_STRING Message
;
154 RtlInitUnicodeString(&Message
, lpMessage
);
158 dwError
= BaseInitiateSystemShutdown((PREGISTRY_SERVER_NAME
)lpMachineName
,
159 (PRPC_UNICODE_STRING
)&Message
,
162 bRebootAfterShutdown
);
164 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
166 dwError
= RtlNtStatusToDosError(RpcExceptionCode());
170 if (dwError
!= ERROR_SUCCESS
)
172 TRACE("BaseInitiateSystemShutdown() failed (Error %lu)\n", dwError
);
173 SetLastError(dwError
);
181 /******************************************************************************
182 * InitiateSystemShutdownExA [ADVAPI32.@]
184 * see InitiateSystemShutdownExW
187 InitiateSystemShutdownExA(LPSTR lpMachineName
,
190 BOOL bForceAppsClosed
,
191 BOOL bRebootAfterShutdown
,
194 ANSI_STRING MachineNameA
, MessageA
;
195 UNICODE_STRING MachineNameW
, MessageW
;
199 MachineNameW
.Buffer
= NULL
;
200 MessageW
.Buffer
= NULL
;
204 RtlInitAnsiString(&MachineNameA
, lpMachineName
);
205 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
206 if (STATUS_SUCCESS
!= Status
)
208 if(MachineNameW
.Buffer
)
209 RtlFreeUnicodeString(&MachineNameW
);
211 SetLastError(RtlNtStatusToDosError(Status
));
218 RtlInitAnsiString(&MessageA
, lpMessage
);
219 Status
= RtlAnsiStringToUnicodeString(&MessageW
, &MessageA
, TRUE
);
220 if (STATUS_SUCCESS
!= Status
)
223 RtlFreeUnicodeString(&MessageW
);
225 SetLastError(RtlNtStatusToDosError(Status
));
230 res
= InitiateSystemShutdownExW(MachineNameW
.Buffer
,
234 bRebootAfterShutdown
,
237 /* Clear the values of both strings */
239 RtlFreeUnicodeString(&MachineNameW
);
242 RtlFreeUnicodeString(&MessageW
);
248 /******************************************************************************
249 * InitiateSystemShutdownExW [ADVAPI32.@]
254 InitiateSystemShutdownExW(LPWSTR lpMachineName
,
257 BOOL bForceAppsClosed
,
258 BOOL bRebootAfterShutdown
,
261 UNICODE_STRING Message
;
264 RtlInitUnicodeString(&Message
, lpMessage
);
268 dwError
= BaseInitiateSystemShutdownEx((PREGISTRY_SERVER_NAME
)lpMachineName
,
269 (PRPC_UNICODE_STRING
)&Message
,
272 bRebootAfterShutdown
,
275 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
277 dwError
= RpcExceptionCode();
281 if (dwError
!= ERROR_SUCCESS
)
283 TRACE("BaseInitiateSystemShutdownEx() failed (Error %lu)\n", dwError
);
284 SetLastError(dwError
);
292 /******************************************************************************
293 * InitiateShutdownW [ADVAPI32.@]
298 InitiateShutdownW(LPWSTR lpMachineName
,
301 DWORD dwShutdownFlags
,
305 return ERROR_SUCCESS
;
308 /******************************************************************************
309 * InitiateShutdownA [ADVAPI32.@]
311 * see InitiateShutdownW
314 InitiateShutdownA(LPSTR lpMachineName
,
317 DWORD dwShutdownFlags
,
320 ANSI_STRING MachineNameA
, MessageA
;
321 UNICODE_STRING MachineNameW
, MessageW
;
326 MachineNameW
.Buffer
= NULL
;
327 MessageW
.Buffer
= NULL
;
331 RtlInitAnsiString(&MachineNameA
, lpMachineName
);
332 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
333 if (STATUS_SUCCESS
!= Status
)
335 if(MachineNameW
.Buffer
)
336 RtlFreeUnicodeString(&MachineNameW
);
338 SetLastError(RtlNtStatusToDosError(Status
));
345 RtlInitAnsiString(&MessageA
, lpMessage
);
346 Status
= RtlAnsiStringToUnicodeString(&MessageW
, &MessageA
, TRUE
);
347 if (STATUS_SUCCESS
!= Status
)
350 RtlFreeUnicodeString(&MessageW
);
352 SetLastError(RtlNtStatusToDosError(Status
));
357 rv
= InitiateShutdownW(MachineNameW
.Buffer
,
362 LastError
= GetLastError();
364 /* Clear the values of both strings */
366 RtlFreeUnicodeString(&MachineNameW
);
369 RtlFreeUnicodeString(&MessageW
);
371 SetLastError(LastError
);