vc 关闭重启注销
Posted nnsword
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vc 关闭重启注销相关的知识,希望对你有一定的参考价值。
- void CXMOperComputerDlg::OnBtnLogout()
- // TODO: Add your control notification handler code here
- HANDLE htoken;
- TOKEN_PRIVILEGES tkp;
- //获得进程标识
- if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&htoken))
- MessageBox("打开进程成功");
- //获得关闭优先权 LUID
- 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 (GetLastError()!=ERROR_SUCCESS)
- MessageBox("获得关闭进程优先权成功");
- if (!ExitWindowsEx(EWX_LOGOFF,0))
- MessageBox("注销");
- void CXMOperComputerDlg::OnBtnreset()
- // TODO: Add your control notification handler code here
- HANDLE htoken;
- TOKEN_PRIVILEGES tkp;
- //获得进程标识
- if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&htoken))
- MessageBox("打开进程成功");
- //获得关闭优先权 LUID
- 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 (GetLastError()!=ERROR_SUCCESS)
- MessageBox("获得关闭进程优先权成功");
- if (!ExitWindowsEx(EWX_REBOOT,0))
- MessageBox("重启计算机");
- void CXMOperComputerDlg::OnBtnShutpc()
- // TODO: Add your control notification handler code here
- HANDLE htoken;
- TOKEN_PRIVILEGES tkp;
- //获得进程标识
- if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&htoken))
- MessageBox("打开进程成功");
- //获得关闭优先权 LUID
- 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 (GetLastError()!=ERROR_SUCCESS)
- MessageBox("获得关闭进程优先权成功");
- if (!ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,0))
- MessageBox("关闭计算机");
以上是关于vc 关闭重启注销的主要内容,如果未能解决你的问题,请参考以下文章