Windows 2000还是WIN32,还是用ExitWindowsEx。

解决方案 »

  1.   


    BOOL ExitWindowsEx(
      UINT uFlags,       // shutdown operation
      DWORD dwReserved   // reserved
    );
     uFlags 
    Specifies the type of shutdown. This parameter must include one of the following values: Value Meaning 
    EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off. 
    EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.
    Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. 
     
    EWX_REBOOT Shuts down the system and then restarts the system. 
    Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. 
     
    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. 
    Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. 
     
    This parameter can optionally include the following values: Value Meaning 
    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. 
    EWX_FORCEIFHUNG Windows NT 5.0 and later: Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used. 
      

  2.   

    在W2K中关机会失败,原因是应用程序权限不够。我想只有设法改变权限才行。
    查查以Access开头的API吧。
      

  3.   

    查一下<<windows API>>
      

  4.   

      Win2000关机与WIN NT4.0关机应该是一致的因为Win2000其实是Win NT5.0。具体方法可以参见《新潮电子》第四期的文章《VC++实现退出Win NT》
      

  5.   

    你需取得授权。这是我的一段源程序:
    OSVERSIONINFO oi;
    oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&oi);
    if (oi.dwPlatformId == VER_PLATFORM_WIN32_NT)
    //if ((ver & 0x0000ffff) == ver  and  and  (ver & 0x0000ffff) == 5)
    {
    HANDLE handle;
    TOKEN_PRIVILEGES tkp; OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES  and  TOKEN_QUERY, &handle);
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
    AdjustTokenPrivileges(handle, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
    }
    ::ExitWindowsEx(flag, 0);注:其中的flag是我在前边定义的,根据选选择是重起机还是关机设定。这段程序可在NT和2000下运行。