为什么找不到ExitWindows函数的详细介绍?而且调用后只是注销不能重启?
能找到ExitWindows函数但是好像这个函数不起作用
为什么找不到ExitWindows函数的详细介绍?而且调用后只是注销不能重启?
答案:1 悬赏:20 手机版
解决时间 2021-02-03 14:19
- 提问者网友:风月客
- 2021-02-02 18:57
最佳答案
- 五星知识达人网友:猎心人
- 2021-02-02 19:24
需要更改权限
void ShutDown()
{
if (dwVersion < 0x80000000)
{
TOKEN_PRIVILEGES tkp,tkpnewbutignored;
HANDLE hdltokenhandle;
LUID tmpluid;
BOOL rc;
DWORD lbufferneeded;
HANDLE hdlprocesshandle = GetCurrentProcess();
rc = OpenProcessToken(hdlprocesshandle,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hdltokenhandle);
rc = LookupPrivilegeValue("","SeShutdownPrivilege", &tmpluid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Luid = tmpluid;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
rc = AdjustTokenPrivileges(hdltokenhandle,FALSE,&tkp,sizeof(tkpnewbutignored),&tkpnewbutignored, &lbufferneeded);
ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE, 0);
}
else
{
ExitWindowsEx(EWX_SHUTDOWN,0);
}
}
void ShutDown()
{
if (dwVersion < 0x80000000)
{
TOKEN_PRIVILEGES tkp,tkpnewbutignored;
HANDLE hdltokenhandle;
LUID tmpluid;
BOOL rc;
DWORD lbufferneeded;
HANDLE hdlprocesshandle = GetCurrentProcess();
rc = OpenProcessToken(hdlprocesshandle,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hdltokenhandle);
rc = LookupPrivilegeValue("","SeShutdownPrivilege", &tmpluid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Luid = tmpluid;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
rc = AdjustTokenPrivileges(hdltokenhandle,FALSE,&tkp,sizeof(tkpnewbutignored),&tkpnewbutignored, &lbufferneeded);
ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE, 0);
}
else
{
ExitWindowsEx(EWX_SHUTDOWN,0);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯