如何用VC实现系统关机、重启、注销?请各位高手指导,
最好有函数参考。
谢啦!

解决方案 »

  1.   

    实现“注销/重启/关机”功能代码:
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;if (FForce) // Forces processes to terminate
    FFlag |= EWX_FORCE;// Get version info to determine operation
    OSVERSIONINFO osvi;
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    if (GetVersionEx(&osvi) == 0)
    return false;// Determine the platform
    if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
    {
    // Windows NT 3.51, Windows NT 4.0, Windows 2000,
    // Windows XP, or Windows .NET Server
    if (!OpenProcessToken(GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    return false; LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1;  // one privilege to set
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
    }ExitWindowsEx(FFlag, 0); 
      

  2.   

    ExitWindowsExWindows NT/2000: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information about security privileges, see Privileges. Windows 95/98: ExitWindowEx does not work from a console application, as it does on Windows NT/Windows 2000. 
      

  3.   

    上面的都说了,在Win98以上需要调整权限,像沙发说的那样。