reboot1.cpp

来自「支持ASP的HTTP服务器代码 ?С諥SP的HTTP服务器代码 ?С諥SP的HT」· C++ 代码 · 共 40 行

CPP
40 行
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?