void RestartPC()
{
char szInfo[1024];
memset(szInfo,0,sizeof(szInfo));
sprintf(szInfo,"重新启动!");
OutputDebugString(szInfo);
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL fResult;
//打开与当前进程相关联的存取标识
if (!::OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES
|TOKEN_QUERY,&hToken))
OutputDebugString("OpenProcessToken failed");
//查出本机系统的当前特权的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)
OutputDebugString("AdjustTokenPrivileges enable failed");
fResult = ::InitiateSystemShutdown(NULL,"即将关机",8,TRUE,TRUE);
if (!fResult)
OutputDebugString("InitiateSystemShutDown failed");
tkp.Privileges[0].Attributes = 0;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
OutputDebugString("AdjustTokenPrivileges disable failed");
}
浙公网安备 33010602011771号