ExitWindowsEx(EWX_LOGOFF¦EWX_FORCEIFHUNG,0)

解决方案 »

  1.   

    同意 Leehunter(理性猎人) ,我在Win98下面实现过。
    请问:如果在Win2000 or WinXP下,也是用同样的函数吗?
      

  2.   

    from http://www.csdn.net/expert/topic/269/269973.xml
    要设置特权级别的。
      给你我的代码:
      
      /*
        *  This  function  is  used  to  shutdown  the  destination  computer.
        *  If  no  computer  name  is  provided,  it  shutdowns  the  current  system.
        */
      bool  ShutDown(DWORD  mode,  LPTSTR  lpMachineName){
      
        bool  flag  =  false;
        HANDLE  tokHandle;  
        if  (OpenProcessToken(GetCurrentProcess(),  
            TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,  &  tokHandle))
        {
          TOKEN_PRIVILEGES  priv;
          priv.PrivilegeCount  =  1;
          priv.Privileges[0].Attributes  =  SE_PRIVILEGE_ENABLED;
          if  (LookupPrivilegeValue(NULL,  SE_SHUTDOWN_NAME,  &  priv.Privileges[0].Luid)
              &  &    AdjustTokenPrivileges(tokHandle,  FALSE,  &  priv,  NULL,  NULL,  NULL)
              &  &    (lpMachineName  ==  NULL  
                ?  ExitWindowsEx(mode,  0)
                :  InitiateSystemShutdown(lpMachineName,
                              NULL,
                              0,
                              (mode  &    EWX_FORCE)  !=  0,
                              (mode  &    EWX_REBOOT)  !=  0)
              )
            )
              flag  =  true;
        }
        return  flag;
      }