fixes
[reactos.git] / reactos / lib / advapi32 / misc / shutdown.c
1 /* $Id: shutdown.c,v 1.2 1999/07/17 23:10:18 ea Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/misc/shutdown.c
6 * PURPOSE: System shutdown functions
7 * PROGRAMMER: Emanuele Aliberti
8 * UPDATE HISTORY:
9 * 19990413 EA created
10 * 19990515 EA
11 */
12
13 #include <windows.h>
14 #include <ddk/ntddk.h>
15
16 #define USZ {0,0,0}
17
18 /**********************************************************************
19 * AbortSystemShutdownW
20 */
21 BOOL
22 STDCALL
23 AbortSystemShutdownW(
24 LPWSTR lpMachineName
25 )
26 {
27 NTSTATUS Status;
28
29 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
30 return FALSE;
31 }
32
33
34 /**********************************************************************
35 * AbortSystemShutdownA
36 */
37 BOOL
38 STDCALL
39 AbortSystemShutdownA(
40 LPSTR lpMachineName
41 )
42 {
43 UNICODE_STRING MachineNameW = USZ;
44 NTSTATUS Status;
45 BOOL rv;
46
47 Status = RtlAnsiStringToUnicodeString(
48 & MachineNameW,
49 lpMachineName,
50 TRUE
51 );
52 if (STATUS_SUCCESS != Status)
53 {
54 SetLastError(RtlNtStatusToDosError(Status));
55 return FALSE;
56 }
57 rv = AbortSystemShutdownW(
58 MachineNameW.Buffer
59 );
60 RtlFreeUnicodeString(
61 & MachineNameW
62 );
63 SetLastError(ERROR_SUCCESS);
64 return rv;
65 }
66
67
68 /**********************************************************************
69 * InitiateSystemShutdownW
70 */
71 BOOL
72 STDCALL
73 InitiateSystemShutdownW(
74 LPWSTR lpMachineName,
75 LPWSTR lpMessage,
76 DWORD dwTimeout,
77 BOOL bForceAppsClosed,
78 BOOL bRebootAfterShutdown
79 )
80 {
81 SHUTDOWN_ACTION Action = ShutdownNoReboot;
82 NTSTATUS Status;
83
84 if (lpMachineName)
85 {
86 /* FIXME: remote machine shutdown not supported yet */
87 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
88 return FALSE;
89 }
90 if (dwTimeout)
91 {
92 }
93 Status = NtShutdownSystem(Action);
94 SetLastError(RtlNtStatusToDosError(Status));
95 return FALSE;
96 }
97
98
99 /**********************************************************************
100 * InitiateSystemShutdownA
101 */
102 BOOL
103 STDCALL
104 InitiateSystemShutdownA(
105 LPSTR lpMachineName,
106 LPSTR lpMessage,
107 DWORD dwTimeout,
108 BOOL bForceAppsClosed,
109 BOOL bRebootAfterShutdown
110 )
111 {
112 UNICODE_STRING MachineNameW = USZ;
113 UNICODE_STRING MessageW = USZ;
114 NTSTATUS Status;
115 INT LastError;
116 BOOL rv;
117
118 if (lpMachineName)
119 {
120 Status = RtlAnsiStringToUnicodeString(
121 & MachineNameW,
122 lpMachineName,
123 TRUE
124 );
125 if (STATUS_SUCCESS != Status)
126 {
127 SetLastError(RtlNtStatusToDosError(Status));
128 return FALSE;
129 }
130 }
131 if (lpMessage)
132 {
133 Status = RtlAnsiStringToUnicodeString(
134 & MessageW,
135 lpMessage,
136 TRUE
137 );
138 if (STATUS_SUCCESS != Status)
139 {
140 if (MachineNameW.Length)
141 {
142 RtlFreeUnicodeString(&MachineNameW);
143 }
144 SetLastError(RtlNtStatusToDosError(Status));
145 return FALSE;
146 }
147 }
148 rv = InitiateSystemShutdownW(
149 MachineNameW.Buffer,
150 MessageW.Buffer,
151 dwTimeout,
152 bForceAppsClosed,
153 bRebootAfterShutdown
154 );
155 LastError = GetLastError();
156 if (MachineNameW.Length) RtlFreeUnicodeString(&MachineNameW);
157 if (MessageW.Length) RtlFreeUnicodeString(&MessageW);
158 SetLastError(LastError);
159 return rv;
160 }
161
162
163 /* EOF */
164