reactos/rostests/rosautotest/shutdown.c
Colin Finck d2148478c6 Introducing the "ReactOS Automatic Testing Utility", superseding our current syssetup/cmd/dbgprint hack for running automatic regression tests.
Without any parameters, it mostly works the same as our current solution, but all in a standalone application.
Adding the /w parameter will submit all results to the web service committed in my previous commit.

The application would also make it possible to run Wine Tests regularly on a Windows machine and submitting the results.
This would make sure that all Wine tests also pass under Windows.

svn path=/trunk/; revision=38580
2009-01-05 12:41:34 +00:00

53 lines
1.5 KiB
C

/*
* PROJECT: ReactOS Automatic Testing Utility
* LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
* PURPOSE: Helper function for shutting down the system
* COPYRIGHT: Copyright 2008-2009 Colin Finck <colin@reactos.org>
*/
#include "precomp.h"
/**
* Shuts down the system.
*
* @return
* TRUE if everything went well, FALSE if there was a problem while trying to shut down the system.
*/
BOOL ShutdownSystem()
{
HANDLE hToken;
TOKEN_PRIVILEGES Privileges;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
StringOut("OpenProcessToken failed\n");
return FALSE;
}
/* Get the LUID for the Shutdown privilege */
if (!LookupPrivilegeValueW(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid))
{
StringOut("LookupPrivilegeValue failed\n");
return FALSE;
}
/* 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))
{
StringOut("AdjustTokenPrivileges failed\n");
return FALSE;
}
/* Finally shut down the system */
if(!ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
{
StringOut("ExitWindowsEx failed\n");
return FALSE;
}
return TRUE;
}