[ADVAPI32]
[reactos.git] / reactos / dll / win32 / advapi32 / misc / shutdown.c
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 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
12
13 #define USZ {0,0,0}
14
15 /**********************************************************************
16 * AbortSystemShutdownW
17 *
18 * @unimplemented
19 */
20 BOOL WINAPI
21 AbortSystemShutdownW(LPCWSTR lpMachineName)
22 {
23 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
24 return FALSE;
25 }
26
27
28 /**********************************************************************
29 * AbortSystemShutdownA
30 *
31 * @unimplemented
32 */
33 BOOL WINAPI
34 AbortSystemShutdownA(LPCSTR lpMachineName)
35 {
36 ANSI_STRING MachineNameA;
37 UNICODE_STRING MachineNameW;
38 NTSTATUS Status;
39 BOOL rv;
40
41 RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName);
42 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
43 if (STATUS_SUCCESS != Status)
44 {
45 SetLastError(RtlNtStatusToDosError(Status));
46 return FALSE;
47 }
48
49 rv = AbortSystemShutdownW(MachineNameW.Buffer);
50 RtlFreeUnicodeString(&MachineNameW);
51 SetLastError(ERROR_SUCCESS);
52 return rv;
53 }
54
55 /**********************************************************************
56 * InitiateSystemShutdownW
57 *
58 * @implemented
59 */
60 BOOL WINAPI
61 InitiateSystemShutdownW(LPWSTR lpMachineName,
62 LPWSTR lpMessage,
63 DWORD dwTimeout,
64 BOOL bForceAppsClosed,
65 BOOL bRebootAfterShutdown)
66 {
67 return InitiateSystemShutdownExW(lpMachineName,
68 lpMessage,
69 dwTimeout,
70 bForceAppsClosed,
71 bRebootAfterShutdown,
72 SHTDN_REASON_MAJOR_OTHER |
73 SHTDN_REASON_MINOR_OTHER |
74 SHTDN_REASON_FLAG_PLANNED);
75 }
76
77 /**********************************************************************
78 * InitiateSystemShutdownA
79 *
80 * @implemented
81 */
82 BOOL
83 WINAPI
84 InitiateSystemShutdownA(LPSTR lpMachineName,
85 LPSTR lpMessage,
86 DWORD dwTimeout,
87 BOOL bForceAppsClosed,
88 BOOL bRebootAfterShutdown)
89 {
90 return InitiateSystemShutdownExA(lpMachineName,
91 lpMessage,
92 dwTimeout,
93 bForceAppsClosed,
94 bRebootAfterShutdown,
95 SHTDN_REASON_MAJOR_OTHER |
96 SHTDN_REASON_MINOR_OTHER |
97 SHTDN_REASON_FLAG_PLANNED);
98 }
99
100 /******************************************************************************
101 * InitiateSystemShutdownExW [ADVAPI32.@]
102 *
103 * @unimplemented
104 */
105 BOOL WINAPI
106 InitiateSystemShutdownExW(LPWSTR lpMachineName,
107 LPWSTR lpMessage,
108 DWORD dwTimeout,
109 BOOL bForceAppsClosed,
110 BOOL bRebootAfterShutdown,
111 DWORD dwReason)
112 {
113 SHUTDOWN_ACTION Action = ShutdownNoReboot;
114 NTSTATUS Status;
115
116 if (lpMachineName)
117 {
118 /* FIXME: remote machine shutdown not supported yet */
119 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
120 return FALSE;
121 }
122
123 if (dwTimeout)
124 {
125 }
126
127 Status = NtShutdownSystem(Action);
128 SetLastError(RtlNtStatusToDosError(Status));
129 return FALSE;
130 }
131
132 /******************************************************************************
133 * InitiateSystemShutdownExA [ADVAPI32.@]
134 *
135 * see InitiateSystemShutdownExW
136 */
137 BOOL WINAPI
138 InitiateSystemShutdownExA(LPSTR lpMachineName,
139 LPSTR lpMessage,
140 DWORD dwTimeout,
141 BOOL bForceAppsClosed,
142 BOOL bRebootAfterShutdown,
143 DWORD dwReason)
144 {
145 ANSI_STRING MachineNameA, MessageA;
146 UNICODE_STRING MachineNameW, MessageW;
147 NTSTATUS Status;
148 INT LastError;
149 BOOL rv;
150
151 MachineNameW.Buffer = NULL;
152 MessageW.Buffer = NULL;
153
154 if (lpMachineName)
155 {
156 RtlInitAnsiString(&MachineNameA, lpMachineName);
157 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
158 if (STATUS_SUCCESS != Status)
159 {
160 if(MachineNameW.Buffer)
161 RtlFreeUnicodeString(&MachineNameW);
162
163 SetLastError(RtlNtStatusToDosError(Status));
164 return FALSE;
165 }
166 }
167
168 if (lpMessage)
169 {
170 RtlInitAnsiString(&MessageA, lpMessage);
171 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
172 if (STATUS_SUCCESS != Status)
173 {
174 if (MessageW.Buffer)
175 RtlFreeUnicodeString(&MessageW);
176
177 SetLastError(RtlNtStatusToDosError(Status));
178 return FALSE;
179 }
180 }
181
182 rv = InitiateSystemShutdownExW(MachineNameW.Buffer,
183 MessageW.Buffer,
184 dwTimeout,
185 bForceAppsClosed,
186 bRebootAfterShutdown,
187 dwReason);
188 LastError = GetLastError();
189 if (lpMachineName)
190 RtlFreeUnicodeString(&MachineNameW);
191
192 if (lpMessage)
193 RtlFreeUnicodeString(&MessageW);
194
195 SetLastError(LastError);
196 return rv;
197 }
198
199 /******************************************************************************
200 * InitiateShutdownW [ADVAPI32.@]
201 *
202 * @unimplamented
203 */
204 DWORD WINAPI
205 InitiateShutdownW(LPWSTR lpMachineName,
206 LPWSTR lpMessage,
207 DWORD dwGracePeriod,
208 DWORD dwShutdownFlags,
209 DWORD dwReason)
210 {
211 UNIMPLEMENTED;
212 return ERROR_SUCCESS;
213 }
214
215 /******************************************************************************
216 * InitiateShutdownA [ADVAPI32.@]
217 *
218 * @unimplamented
219 */
220 DWORD WINAPI
221 InitiateShutdownA(LPSTR lpMachineName,
222 LPSTR lpMessage,
223 DWORD dwGracePeriod,
224 DWORD dwShutdownFlags,
225 DWORD dwReason)
226 {
227 ANSI_STRING MachineNameA, MessageA;
228 UNICODE_STRING MachineNameW, MessageW;
229 NTSTATUS Status;
230 INT LastError;
231 DWORD rv;
232
233 MachineNameW.Buffer = NULL;
234 MessageW.Buffer = NULL;
235
236 if (lpMachineName)
237 {
238 RtlInitAnsiString(&MachineNameA, lpMachineName);
239 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
240 if (STATUS_SUCCESS != Status)
241 {
242 if(MachineNameW.Buffer)
243 RtlFreeUnicodeString(&MachineNameW);
244
245 SetLastError(RtlNtStatusToDosError(Status));
246 return FALSE;
247 }
248 }
249
250 if (lpMessage)
251 {
252 RtlInitAnsiString(&MessageA, lpMessage);
253 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
254 if (STATUS_SUCCESS != Status)
255 {
256 if (MessageW.Buffer)
257 RtlFreeUnicodeString(&MessageW);
258
259 SetLastError(RtlNtStatusToDosError(Status));
260 return FALSE;
261 }
262 }
263
264 rv = InitiateShutdownW(MachineNameW.Buffer,
265 MessageW.Buffer,
266 dwGracePeriod,
267 dwShutdownFlags,
268 dwReason);
269 LastError = GetLastError();
270 if (lpMachineName)
271 RtlFreeUnicodeString(&MachineNameW);
272
273 if (lpMessage)
274 RtlFreeUnicodeString(&MessageW);
275
276 SetLastError(LastError);
277 return rv;
278 }
279
280 /* EOF */