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 #include <ndk/exfuncs.h>
14 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
16 /**********************************************************************
17 * AbortSystemShutdownW
22 AbortSystemShutdownW(LPCWSTR lpMachineName
)
24 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
29 /**********************************************************************
30 * AbortSystemShutdownA
32 * see AbortSystemShutdownW
35 AbortSystemShutdownA(LPCSTR lpMachineName
)
37 ANSI_STRING MachineNameA
;
38 UNICODE_STRING MachineNameW
;
42 RtlInitAnsiString(&MachineNameA
, (LPSTR
)lpMachineName
);
43 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
44 if (STATUS_SUCCESS
!= Status
)
46 SetLastError(RtlNtStatusToDosError(Status
));
50 rv
= AbortSystemShutdownW(MachineNameW
.Buffer
);
51 RtlFreeUnicodeString(&MachineNameW
);
52 SetLastError(ERROR_SUCCESS
);
56 /**********************************************************************
57 * InitiateSystemShutdownW
62 InitiateSystemShutdownW(LPWSTR lpMachineName
,
65 BOOL bForceAppsClosed
,
66 BOOL bRebootAfterShutdown
)
68 return InitiateSystemShutdownExW(lpMachineName
,
73 SHTDN_REASON_MAJOR_OTHER
|
74 SHTDN_REASON_MINOR_OTHER
|
75 SHTDN_REASON_FLAG_PLANNED
76 /* SHTDN_REASON_MAJOR_LEGACY_API */);
79 /**********************************************************************
80 * InitiateSystemShutdownA
86 InitiateSystemShutdownA(LPSTR lpMachineName
,
89 BOOL bForceAppsClosed
,
90 BOOL bRebootAfterShutdown
)
92 return InitiateSystemShutdownExA(lpMachineName
,
97 SHTDN_REASON_MAJOR_OTHER
|
98 SHTDN_REASON_MINOR_OTHER
|
99 SHTDN_REASON_FLAG_PLANNED
100 /* SHTDN_REASON_MAJOR_LEGACY_API */);
103 /******************************************************************************
104 * InitiateSystemShutdownExW [ADVAPI32.@]
109 InitiateSystemShutdownExW(LPWSTR lpMachineName
,
112 BOOL bForceAppsClosed
,
113 BOOL bRebootAfterShutdown
,
116 SHUTDOWN_ACTION action
;
120 DBG_UNREFERENCED_LOCAL_VARIABLE(Timeout_ms
);
122 /* Convert to milliseconds so we can use the value later on */
123 Timeout_ms
= dwTimeout
* 1000;
125 if (lpMachineName
!= NULL
)
127 /* FIXME: Remote system shutdown not supported yet */
128 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
131 else /* The local system is being used */
133 /* FIXME: Right now, only basic shutting down and rebooting
135 if(bRebootAfterShutdown
== TRUE
)
137 action
= ShutdownReboot
;
141 action
= ShutdownNoReboot
;
144 Status
= NtShutdownSystem(action
);
147 SetLastError(RtlNtStatusToDosError(Status
));
148 return (Status
== STATUS_SUCCESS
);
151 /******************************************************************************
152 * InitiateSystemShutdownExA [ADVAPI32.@]
154 * see InitiateSystemShutdownExW
157 InitiateSystemShutdownExA(LPSTR lpMachineName
,
160 BOOL bForceAppsClosed
,
161 BOOL bRebootAfterShutdown
,
164 ANSI_STRING MachineNameA
, MessageA
;
165 UNICODE_STRING MachineNameW
, MessageW
;
170 MachineNameW
.Buffer
= NULL
;
171 MessageW
.Buffer
= NULL
;
175 RtlInitAnsiString(&MachineNameA
, lpMachineName
);
176 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
177 if (STATUS_SUCCESS
!= Status
)
179 if(MachineNameW
.Buffer
)
180 RtlFreeUnicodeString(&MachineNameW
);
182 SetLastError(RtlNtStatusToDosError(Status
));
189 RtlInitAnsiString(&MessageA
, lpMessage
);
190 Status
= RtlAnsiStringToUnicodeString(&MessageW
, &MessageA
, TRUE
);
191 if (STATUS_SUCCESS
!= Status
)
194 RtlFreeUnicodeString(&MessageW
);
196 SetLastError(RtlNtStatusToDosError(Status
));
201 rv
= InitiateSystemShutdownExW(MachineNameW
.Buffer
,
205 bRebootAfterShutdown
,
207 LastError
= GetLastError();
209 /* Clear the values of both strings */
211 RtlFreeUnicodeString(&MachineNameW
);
214 RtlFreeUnicodeString(&MessageW
);
216 SetLastError(LastError
);
220 /******************************************************************************
221 * InitiateShutdownW [ADVAPI32.@]
226 InitiateShutdownW(LPWSTR lpMachineName
,
229 DWORD dwShutdownFlags
,
233 return ERROR_SUCCESS
;
236 /******************************************************************************
237 * InitiateShutdownA [ADVAPI32.@]
239 * see InitiateShutdownW
242 InitiateShutdownA(LPSTR lpMachineName
,
245 DWORD dwShutdownFlags
,
248 ANSI_STRING MachineNameA
, MessageA
;
249 UNICODE_STRING MachineNameW
, MessageW
;
254 MachineNameW
.Buffer
= NULL
;
255 MessageW
.Buffer
= NULL
;
259 RtlInitAnsiString(&MachineNameA
, lpMachineName
);
260 Status
= RtlAnsiStringToUnicodeString(&MachineNameW
, &MachineNameA
, TRUE
);
261 if (STATUS_SUCCESS
!= Status
)
263 if(MachineNameW
.Buffer
)
264 RtlFreeUnicodeString(&MachineNameW
);
266 SetLastError(RtlNtStatusToDosError(Status
));
273 RtlInitAnsiString(&MessageA
, lpMessage
);
274 Status
= RtlAnsiStringToUnicodeString(&MessageW
, &MessageA
, TRUE
);
275 if (STATUS_SUCCESS
!= Status
)
278 RtlFreeUnicodeString(&MessageW
);
280 SetLastError(RtlNtStatusToDosError(Status
));
285 rv
= InitiateShutdownW(MachineNameW
.Buffer
,
290 LastError
= GetLastError();
292 /* Clear the values of both strings */
294 RtlFreeUnicodeString(&MachineNameW
);
297 RtlFreeUnicodeString(&MessageW
);
299 SetLastError(LastError
);