win95与win2000的关机与重启

发表于:2007-07-01来源:作者:点击数: 标签:
VOID ShutDownProcess ( VOID )//关机程序 { if ( Is Windows 9x() ) { ExitWindowsEx( EWX_SHU TD OWN | EWX_FORCE, 0); } else { HANDLE hToken; TOKEN_PRIVILEGES tkp; if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUE

 

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);
 }  
 }
}


原文转自:http://www.ltesting.net