ReactOS 0.4.15-dev-8219-ge8b88cf
shutdown.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Helper function for shutting down the system
5 * COPYRIGHT: Copyright 2008-2009 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9
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
bool ShutdownSystem()
Definition: shutdown.cpp:16
#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