2009-01-05 12:41:34 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Automatic Testing Utility
|
2017-09-29 18:13:54 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2009-01-05 12:41:34 +00:00
|
|
|
* PURPOSE: Helper function for shutting down the system
|
2017-09-29 18:13:54 +00:00
|
|
|
* COPYRIGHT: Copyright 2008-2009 Colin Finck (colin@reactos.org)
|
2009-01-05 12:41:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shuts down the system.
|
|
|
|
*
|
|
|
|
* @return
|
2009-03-21 01:39:04 +00:00
|
|
|
* true if everything went well, false if there was a problem while trying to shut down the system.
|
2009-01-05 12:41:34 +00:00
|
|
|
*/
|
2009-03-21 01:39:04 +00:00
|
|
|
bool ShutdownSystem()
|
2009-01-05 12:41:34 +00:00
|
|
|
{
|
|
|
|
HANDLE hToken;
|
|
|
|
TOKEN_PRIVILEGES Privileges;
|
|
|
|
|
|
|
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
|
|
|
{
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut("OpenProcessToken failed\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
return false;
|
2009-01-05 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the LUID for the Shutdown privilege */
|
|
|
|
if (!LookupPrivilegeValueW(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid))
|
|
|
|
{
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut("LookupPrivilegeValue failed\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
return false;
|
2009-01-05 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign the Shutdown privilege to our process */
|
|
|
|
Privileges.PrivilegeCount = 1;
|
|
|
|
Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
|
|
|
|
|
|
if (!AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, NULL, NULL))
|
|
|
|
{
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut("AdjustTokenPrivileges failed\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
return false;
|
2009-01-05 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally shut down the system */
|
|
|
|
if(!ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
|
|
|
|
{
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut("ExitWindowsEx failed\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
return false;
|
2009-01-05 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
2009-03-21 01:39:04 +00:00
|
|
|
return true;
|
2009-01-05 12:41:34 +00:00
|
|
|
}
|