我的系统是win2oooadv 的,我在一个函数中写下这样的代码:
ExitWindowsEx(EWX_SHUTDOWN,0);意图是
void CMainFrame::OnClose() 中调用此函数。
void CMainFrame::OnAppExit()中也调用此函数,可执行结果是只把应用程序自身关了,我把那数字改成1或2都没用,而在别人机子又可以实现关机的功能。

解决方案 »

  1.   

    答案:
    http://www.china-askpro.com/msg12/qa12.shtml
      

  2.   

    The calling process must have the SE_SHUTDOWN_NAME privilege. 
    Or use function :InitiateSystemShutdown
      

  3.   

    ExitWindowsEx(EWX_SHUTDOWN,0);
    后Sleep(3000)试试
      

  4.   

    int ReBoot(int Type, BOOL fForce)
    {

    HANDLE hToken; 
    TOKEN_PRIVILEGES tkp; 

    if ( g_IsNt )
    {
    // Get a token for this process. 

    if (!OpenProcessToken(GetCurrentProcess(), 
    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
    TRACE0("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) 
    TRACE0("AdjustTokenPrivileges"); 
    }
    if ( fForce )
    {
    if ( Type )
    {
    if ( g_IsNt )
    {

    ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,0);
    }
    else
    ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);
    }
    else
    ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0);
    }
    else
    {
    if ( Type )
    {
    if ( g_IsNt )
    {
    ExitWindowsEx(EWX_POWEROFF,0);
    }
    else
    ExitWindowsEx(EWX_SHUTDOWN,0);
    }
    else
         ExitWindowsEx(EWX_REBOOT,0);
    }
       
    return 0;
    }
      

  5.   

    当然有啦,::ExitWindowsEx(EWX_POWEROFF,EWX_FORCE);
      

  6.   

    to SeaSurf(风好扬帆) :
     这个是关机的不是注销系统的!
      

  7.   

    是不是跟操作系统有关系,我在98下是这样用的:
    ExitWindowsEx(EWX_SHUTDOWN, EWX_FORCE); //EWX_SHUTDOWN(关机), EWX_POWEROFF(注销), EWX_REBOOT(重启)
      

  8.   

    我的是2000的,用EWX_POWEROFF是自动关机了,而EWX_SHUTDOWN也是关机但最后要手动关机
      

  9.   

    上面 cnpeople(不吃不喝)老兄的方法应该可以吧?