VOID ShutDownProcess ( VOID ) //关机程序
{
if ( IsWindows9x() ) {
ExitWindowsEx( EWX_SHUTDOWN | EWX_FORCE, 0);
}
else {
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if ( !OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
MessageBox ( NULL , "无法关机",CLASSNAME,MB_OK);
return ;
}
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS) {
MessageBox ( NULL , "无法关机",CLASSNAME,MB_OK);
}
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
MessageBox ( NULL , "无法关机",CLASSNAME,MB_OK);
}
}
}
VOID RebootProcess ( VOID ) //重启程序
{
if ( IsWindows9x() ) {
ExitWindowsEx( EWX_REBOOT | EWX_FORCE, 0);
}
else {
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if ( !OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
MessageBox ( NULL , "无法关机",CLASSNAME,MB_OK);
return ;
}
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS) {
MessageBox ( NULL , "无法关机",CLASSNAME,MB_OK);
}
if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0)) {
MessageBox ( NULL , "无法关机",CLASSNAME,MB_OK);
}
}
}