怎样关闭计算机和重新启动系统?
我用ExitWindowsEx(EWX_SHUTDOWN,0);
ExitWindowsEx(EWX_REBOOT,0);
都没有用。

解决方案 »

  1.   


    试一下
    ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,0);
    ExitWindowsEx(EWX_REBOOT|EWX_FORCE;,0);
      

  2.   

    在win98下可以
    ExitWindowsEx(EWX_SHUTDOWN |EWX_FORCE,NULL);就可以了,
    但是在win2000下这个关机的线程需要一定的权限才有用!
      

  3.   

    试试这个:(98 和 2000 下都可以的)// ExitW.cpp : Defines the entry point for the DLL application.
    //#include "stdafx.h"
    BOOL WINAPI IsWin2000 ();
    BOOL EnablePrivilege(LPTSTR privilege);
    BOOL DisablePrivilege(LPTSTR privilege);
    void WINAPI exitw(int flag);BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
          )
    {
        return TRUE;
    }void WINAPI exitw(int flag)
    {
     // flag 
     // EWX_LOGOFF           0
     // EWX_SHUTDOWN         1
     // EWX_REBOOT           2
     // EWX_POWEROFF         8
     BOOL success;
     if(flag==EWX_LOGOFF) ExitWindowsEx(EWX_LOGOFF, 0); if(IsWin2000 ()) 
     {
      BOOL retval = EnablePrivilege(SE_SHUTDOWN_NAME);
      if(!retval) return;
     }    if(flag==EWX_REBOOT) success = ExitWindowsEx(EWX_REBOOT, 0);
        if(flag==EWX_POWEROFF) success = ExitWindowsEx(EWX_POWEROFF, 0);
        if(flag==EWX_SHUTDOWN) success = ExitWindowsEx(EWX_SHUTDOWN, 0);
     if(IsWin2000 ()) DisablePrivilege(SE_SHUTDOWN_NAME);
    }//=============================================================================
    BOOL EnablePrivilege(LPTSTR privilege)
    {
     BOOL success;
     HANDLE token;
     LUID luid;
     TOKEN_PRIVILEGES tokenPrivileges; // Get token for this process
     success = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token);
     if (!success) 
     {
      return FALSE;
     } // Gets the value for a privilege
     success = LookupPrivilegevalue(0, privilege, &luid);
     if (!success) 
     {
      return FALSE;
     }
     
     // Enable the privilege
     tokenPrivileges.PrivilegeCount = 1;
     tokenPrivileges.Privileges[0].Luid = luid;
     tokenPrivileges.Privileges[0].Attributes =SE_PRIVILEGE_ENABLED;
     success = AdjustTokenPrivileges(token, FALSE,&tokenPrivileges, 0, 0, 0);
     // Always returns true, so check GetLastError
     if (GetLastError() != ERROR_SUCCESS) 
     {
      return FALSE;
     }
     return TRUE;
    }BOOL DisablePrivilege(LPTSTR privilege)
    {
     BOOL success;
     HANDLE token;
     LUID luid;
     TOKEN_PRIVILEGES tokenPrivileges; // Get tokens for this process
     success = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&token);
     if (!success) 
     {
      return FALSE;
     } // Gets the value for a privilege
     success = LookupPrivilegevalue(0, privilege, &luid);
     if (!success) 
     {
      return FALSE;
     } // Disable the privilege
     tokenPrivileges.PrivilegeCount = 1;
     tokenPrivileges.Privileges[0].Luid = luid; // disable the privilege
     tokenPrivileges.Privileges[0].Attributes = 0;
     success = AdjustTokenPrivileges(token, FALSE,&tokenPrivileges, 0, 0, 0); // Always returns true, so...
     if (GetLastError() != ERROR_SUCCESS) 
     {
      return FALSE;
     }
     return TRUE;
    }BOOL WINAPI IsWin2000 () 
    {
     OSVERSIONINFOEX osvi;
     BOOL bOsVersionInfoEx;
     
     ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     
     if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
     {
      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
      if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE;
     }
     
     switch (osvi.dwPlatformId)
     {
     case VER_PLATFORM_WIN32_NT:
      if ( osvi.dwMajorVersion >= 5 ) return TRUE;
      break;
     }
     return FALSE; 
    }
      

  4.   

    to:abigfrog(千年精灵)(PHP初学) 
    LookupPrivilegevalue()这个函数的实现是什么?
      

  5.   

    LookupPrivilegevalue是api,winbase.h中定义的
      

  6.   

    //重新启动
              OSVERSIONINFO osv;
    osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
    GetVersionEx(&osv);
    if(osv.dwPlatformId == VER_PLATFORM_WIN32_NT)
    {
    HANDLE hProcess,hToken;
    TOKEN_PRIVILEGES Privileges;
    LUID luid;
    hProcess=GetCurrentProcess();
    OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
    Privileges.PrivilegeCount=1;
    LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
    Privileges.Privileges[0].Luid=luid;
    Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
    }
    ExitWindowsEx(EWX_REBOOT,0);