ReactOS 0.4.16-dev-109-gf4cb10f
shutdown.cpp File Reference
#include "precomp.h"
Include dependency graph for shutdown.cpp:

Go to the source code of this file.

Functions

bool ShutdownSystem ()
 

Function Documentation

◆ ShutdownSystem()

bool ShutdownSystem ( )

Shuts down the system.

Returns
true if everything went well, false if there was a problem while trying to shut down the system.

Definition at line 16 of file shutdown.cpp.

17{
18 HANDLE hToken;
20
22 {
23 StringOut("OpenProcessToken failed\n");
24 return false;
25 }
26
27 /* Get the LUID for the Shutdown privilege */
28 if (!LookupPrivilegeValueW(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid))
29 {
30 StringOut("LookupPrivilegeValue failed\n");
31 return false;
32 }
33
34 /* Assign the Shutdown privilege to our process */
35 Privileges.PrivilegeCount = 1;
36 Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
37
38 if (!AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, NULL, NULL))
39 {
40 StringOut("AdjustTokenPrivileges failed\n");
41 return false;
42 }
43
44 /* Finally shut down the system */
45 if(!ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
46 {
47 StringOut("ExitWindowsEx failed\n");
48 return false;
49 }
50
51 return true;
52}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
string StringOut(const string &String, bool forcePrint=true)
Definition: tools.cpp:96
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:384
#define EWX_POWEROFF
Definition: winuser.h:637
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:17
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

Referenced by wmain().