|
Borland C ++ Builder FAQ
|
||
| The content | The last update: 12/12/2008 | |
|
How program to ungear the computer? The author: OlegGG bool shoot (bool reboot, bool force)
{
OSVERSIONINFO ver;
ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
GetVersionEx (&ver);
if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT)//in family NT for shut-down it is necessary to have privilege SE_SHUTDOWN_NAME
{
HANDLE hToken;
TOKEN_PRIVILEGES* NewState;
OpenProcessToken (GetCurrentProcess () ,TOKEN_ADJUST_PRIVILEGES,&hToken);
NewState = (TOKEN_PRIVILEGES *) malloc (sizeof (TOKEN_PRIVILEGES) + sizeof (LUID_AND_ATTRIBUTES));
NewState-> PrivilegeCount = 1;
LookupPrivilegeValue (NULL,SE_SHUTDOWN_NAME,&NewState->Privileges [0].Luid);
NewState-> Privileges [0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges (hToken, FALSE, NewState, NULL, NULL, NULL);
free (NewState);
CloseHandle (hToken);
}
UINT mode = 0;
if (reboot)
mode + = EWX_REBOOT;
else
mode + = EWX_POWEROFF;
if (force) mode + = EWX_FORCE;
return ExitWindowsEx (mode, 0);
}
Usage:shoot (false, true);//in "a fast" mode closes all programs and ungears the computer |