ReactOS  0.4.11-dev-721-g95bc44e
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 */
29  {
30  StringOut("LookupPrivilegeValue failed\n");
31  return false;
32  }
33 
34  /* Assign the Shutdown privilege to our process */
35  Privileges.PrivilegeCount = 1;
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 }
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
$ULONG PrivilegeCount
Definition: setypes.h:969
bool ShutdownSystem()
Definition: shutdown.cpp:16
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define EWX_POWEROFF
Definition: winuser.h:632
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
string StringOut(const string &String, bool forcePrint=true)
Definition: tools.cpp:96
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:13
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:372
DWORD *typedef HANDLE
Definition: winlogon.h:61
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:292
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:970
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:383
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876