提交 8e07d092 编写于 作者: 泡沫o0's avatar 泡沫o0 🤖

Upload New File

上级 cb71a7b4
#include "./operation_windows.h"
Operation_Windows::Operation_Windows()
{
}
int Operation_Windows::ScreenOperation(bool commond)
{
#if (defined(Q_CC_MSVC) || defined(Q_CC_MINGW))
if(commond==true)
{
::PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
}
else
{
::PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)-1);
}
#else
Q_UNUSED(commond);
#endif
return 0;
}
bool Operation_Windows::envinit()
{
#if (defined(Q_CC_MSVC) || defined(Q_CC_MINGW))
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
//获取进程标志
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;
//获取关机特权的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) return false;
#endif
return true;
}
int Operation_Windows::PoweroffOperation(int commond)
{
#if (defined(Q_CC_MSVC) || defined(Q_CC_MINGW))
if(envinit() !=0) return -1;
/*****************************************************************/
if(commond == 1)
{
// 强制关闭计算机
if ( !ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
return -1;
}
else if(commond == 2)
{
SetSystemPowerState(false,TRUE);
}
else if(commond == 3)
{
ExitWindowsEx(EWX_REBOOT,0); //重启计算机
}
else {
}
#else
Q_UNUSED(commond);
#endif
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册