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 10 /** 11 * Shuts down the system. 12 * 13 * @return 14 * true if everything went well, false if there was a problem while trying to shut down the system. 15 */ 16 bool ShutdownSystem() 17 { 18 HANDLE hToken; 19 TOKEN_PRIVILEGES Privileges; 20 21 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) 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 } 53