📄 reboot1.cpp
字号:
// REBOOT1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
int main(int argc, char* argv[])
{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");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -