:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / advapi32 / misc / shutdown.c
1 /* $Id$
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         ANSI_STRING     MachineNameA;
44         UNICODE_STRING  MachineNameW;
45         NTSTATUS        Status;
46         BOOL            rv;
47
48         RtlInitAnsiString(
49                         & MachineNameA,
50                         lpMachineName
51                         );
52         Status = RtlAnsiStringToUnicodeString(
53                         & MachineNameW,
54                         & MachineNameA,
55                         TRUE
56                         );
57         if (STATUS_SUCCESS != Status) 
58         {
59                 SetLastError(RtlNtStatusToDosError(Status));
60                 return FALSE;
61         }
62         rv = AbortSystemShutdownW(
63                         MachineNameW.Buffer
64                         );
65         RtlFreeAnsiString(
66                         & MachineNameA
67                         );
68         RtlFreeUnicodeString(
69                         & MachineNameW
70                         );
71         SetLastError(ERROR_SUCCESS);
72         return rv;
73 }
74
75
76 /**********************************************************************
77  *      InitiateSystemShutdownW
78  */
79 BOOL
80 STDCALL
81 InitiateSystemShutdownW(
82         LPWSTR  lpMachineName,
83         LPWSTR  lpMessage,
84         DWORD   dwTimeout,
85         BOOL    bForceAppsClosed,
86         BOOL    bRebootAfterShutdown
87         )
88 {
89         SHUTDOWN_ACTION Action = ShutdownNoReboot;
90         NTSTATUS        Status;
91
92         if (lpMachineName)
93         {
94                 /* FIXME: remote machine shutdown not supported yet */
95                 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
96                 return FALSE;
97         }
98         if (dwTimeout)
99         {
100         }
101         Status = NtShutdownSystem(Action);
102         SetLastError(RtlNtStatusToDosError(Status));
103         return FALSE;
104 }
105
106
107 /**********************************************************************
108  *      InitiateSystemShutdownA
109  */
110 BOOL
111 STDCALL
112 InitiateSystemShutdownA(
113         LPSTR   lpMachineName,
114         LPSTR   lpMessage,
115         DWORD   dwTimeout,
116         BOOL    bForceAppsClosed,
117         BOOL    bRebootAfterShutdown
118         )
119 {
120         ANSI_STRING     MachineNameA;
121         ANSI_STRING     MessageA;
122         UNICODE_STRING  MachineNameW;
123         UNICODE_STRING  MessageW;
124         NTSTATUS        Status;
125         INT             LastError;
126         BOOL            rv;
127
128         if (lpMachineName)
129         {
130                 RtlInitAnsiString(
131                                 & MachineNameA,
132                                 lpMachineName
133                                 );
134                 Status = RtlAnsiStringToUnicodeString(
135                                 & MachineNameW,
136                                 & MachineNameA,
137                                 TRUE
138                                 );
139                 if (STATUS_SUCCESS != Status)
140                 {
141                         RtlFreeAnsiString(&MachineNameA);
142                         SetLastError(RtlNtStatusToDosError(Status));
143                         return FALSE;
144                 }
145         }
146         if (lpMessage)
147         {
148                 RtlInitAnsiString(
149                                 & MessageA,
150                                 lpMessage
151                                 );
152                 Status = RtlAnsiStringToUnicodeString(
153                                 & MessageW,
154                                 & MessageA,
155                                 TRUE
156                                 );
157                 if (STATUS_SUCCESS != Status)
158                 {
159                         if (MachineNameW.Length)
160                         {
161                                 RtlFreeAnsiString(&MachineNameA);
162                                 RtlFreeUnicodeString(&MachineNameW);
163                         }
164                         RtlFreeAnsiString(&MessageA);
165                         SetLastError(RtlNtStatusToDosError(Status));
166                         return FALSE;
167                 }
168         }
169         rv = InitiateSystemShutdownW(
170                         MachineNameW.Buffer,
171                         MessageW.Buffer,
172                         dwTimeout,
173                         bForceAppsClosed,
174                         bRebootAfterShutdown
175                         );
176         LastError = GetLastError();
177         if (lpMachineName)
178         {
179                 RtlFreeAnsiString(&MachineNameA);
180                 RtlFreeUnicodeString(&MachineNameW);
181         }
182         if (lpMessage)
183         {
184                 RtlFreeAnsiString(&MessageA);
185                 RtlFreeUnicodeString(&MessageW);
186         }
187         SetLastError(LastError);
188         return rv;
189 }
190
191
192 /* EOF */
193