码迷,mamicode.com
首页 > 编程语言 > 详细

VC++下实现系统关机、重启

时间:2015-06-30 17:58:14      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

关机调用:

文章来源:http://dqifa.blog.163.com/blog/#m=0&t=1&c=fks_095066086083081065092081074071093084084075087080083
MyExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE | EWX_POWEROFF);


重启调用:


MyExitWindowsEx(EWX_REBOOT | EWX_FORCE); 


具体实现:


BOOL IsWIN32_NT()

{

 OSVERSIONINFO osv;

 osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO;

 GetVersionEx(&osv);

 return osv.dwPlatformId == VER_PLATFORM_WIN32_NT;

}

BOOL MyExitWindowsEx(UINT uFlags)

{

 if(IsWIN32_NT())

 {

  HANDLE hProcess, hToken;

  TOKEN_PRIVILEGES Privileges;

  hProcess = GetCurrentProcess();

  OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);

  LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid);

  Privileges.PrivilegeCount = 1;

  Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

  AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, (PTOKEN_PRIVILEGES)NULL, NULL);

 }

 return ExitWindowsEx(uFlags, 0);

}

VC++下实现系统关机、重启

标签:

原文地址:http://www.cnblogs.com/yuqilihualuo/p/4611006.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!