为什么我用ExitWindowsEx( EWX_SHUTDOWN | EWX_FORCE, 0 );强制关机后,再启动时会显示白屏,要重置桌面,有时还会重新scandisk,就好象非法关机一样,而且有时还关不掉电源,只是把显示器关黑了。

解决方案 »

  1.   

    EWX_FORCE 
    Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
      

  2.   

    ExitWindowsEx( EWX_SHUTDOWN,0 )
      

  3.   

    但我就是需要强制关机,服务端发命令关机不管客户端愿意不愿意都要关,如果用EWX_SHUTDOWN 那如果客户端有一个编辑程序没存盘,会有对话框提示存盘,如果用户按了[取消]那么客户端机器就不关了,这不是我想要的结果。
      

  4.   

    因为没有权限From MSDN
    Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. From re
    Windows NT: To shut down or restart the system, the calling process must use theAdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information about security privileges, seePrivileges. it means void CShutdownDlg::OnButton1() 
    {
    HANDLE hdl;  
    OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hdl);  
      PTOKEN_PRIVILEGES ptoken = (PTOKEN_PRIVILEGES) new BYTE[sizeof(DWORD) +  
    sizeof(LUID_AND_ATTRIBUTES)];  
    ptoken->PrivilegeCount = 1;  
    LUID uid;  
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &uid);   ptoken->Privileges[0].Luid = uid;  
    ptoken->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;  
    AdjustTokenPrivileges(hdl, FALSE, ptoken, 0, NULL, NULL);    //向进程表内写入数据
      CloseHandle(hdl);  
    delete [](BYTE *)ptoken;  
    ExitWindowsEx(EWX_FORCE|EWX_POWEROFF,0);
    }
      

  5.   

    下面一段是win2000的关机程序HANDLE hToken; 
    TOKEN_PRIVILEGES tkp; 
     
    // Get a token for this process. 
     
    if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
        AfxMessageBox("OpenProcessToken"); 
     
    // Get the LUID for the shutdown privilege. 
     
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
            &tkp.Privileges[0].Luid); 
     
    tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
    // Get the shutdown privilege for this process. 
     
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
     
    // Cannot test the return value of AdjustTokenPrivileges. 
     
    if (GetLastError() != ERROR_SUCCESS) 
        AfxMessageBox("AdjustTokenPrivileges"); 
     
    // Shut down the system and force all applications to close. 
     
    ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0); 
      

  6.   

    没有权限,象win98有那么严格要求吗?这个APIwin98也支持的。
    如果是win2000的话当然需要楼上的那种了
      

  7.   

    win98不需要象win2000那样需要关机权限。
    ExitWindowsEx(EWX_POWEROFF|EWX_FORCE,0);
      

  8.   

    sunyou(sunyou) 老兄你真搞笑, 我的问题就是为什么用ExitWindowsEx(EWX_POWEROFF|EWX_FORCE,0);关不掉啊 :)你这话等于没说一样
      

  9.   

    你问题描述中用的什么参数,是我老眼昏花看错了吗?EWX_SHUTDOWN
    Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. If the system supports the power-off feature, the power is also turned off. EWX_POWEROFF
    Shuts down the system and turns off the power. The system must support the power-off feature. EWX_FORCE
    Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
      

  10.   

    对不起,我看错了,不过我试了用你说的POWEROFF更不行耶,用SHUTDOWN还能关掉,用这个根本就关不掉,频频出现非法窗口(我装了softice),还死掉。:(
      

  11.   

    EWX_POWEROFF|EWX_SHUTDOWN
    最好不要用EWX_FORCE,因为不会给应用程序发消息,容易丢失数据。
    另外,楼上说的关机补丁可能很重要。