Windows 2000下如何在自己的程序中实现关机!

if(m_nReboot==0)
    {
        if(ExitWindowsEx(EWX_REBOOT, 0)) goto Exit;
        if(ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0)) goto Exit;
        //因为上面的重起不成功,所以需要调整本进程的特权
        HANDLE hToken;
        TOKEN_PRIVILEGES tkp;
        if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken)) goto Exit;
        //获取重起的特权SE_SHUTDOWN_NAME
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);

        if (!ExitWindowsEx(EWX_REBOOT, 0))
            ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
    }

Exit:
    CDialog::OnClose();
posted @ 2005-04-13 13:41  至尊王者  阅读(1096)  评论(2编辑  收藏  举报