Shutdown.cpp ( 文件浏览 )
- keepall 发布于 2016-08-23 22:14
- 浏览次数:450
- 下载次数: 1
- 下载需 10 积分
-
- 侵权举报
#include "stdafx.h" #include "Shutdown.h" #include "reason.h" #include "resource.h" bool InitPrivileges() { HANDLE token; TOKEN_PRIVILEGES tkp; if(!::OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&token)) return false; ::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid); tkp.PrivilegeCount=1; tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; if(!AdjustTokenPrivileges(token,false,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0)) return false; if(GetLastError()!=ERROR_SUCCESS) return false; return true; } bool kgdShutdown(bool bShutdown) { InitPrivileges(); if(bShutdown) { if(!ExitWindowsEx(EWX_FORCE|EWX_SHUTDOWN,SHTDN_REASON_MAJOR_OPERATINGSYSTEM|SHTDN_REASON_MINOR_UPGRADE| SHTDN_REASON_FLAG_PLANNED)) return false; } else { if(!ExitWindowsEx(EWX_FORCE|EWX_REBOOT,SHTDN_REASON_MAJOR_OPERATINGSYSTEM|SHTDN_REASON_MINOR_UPGRADE| SHTDN_REASON_FLAG_PLANNED)) return false; } return true; } void kgdHibernate(bool bHibernate) { InitPrivileges(); if(bHibernate) { SetSystemPowerState(false,true); } else { SetSystemPowerState(true,true); } } void ShutdownComputer(ShutdownOption so) { switch(so) { case Shutdown: kgdShutdown(true); break; case Reboot: kgdShutdown(false); break; case Logoff: ::ExitWindowsEx(EWX_FORCE|EWX_LOGOFF,0); break; case LockScreen: ::LockWorkStation(); break; case Hibernate: kgdHibernate(true); break; case Suspend: kgdHibernate(false); break; } }
...
展开> <收缩
Sponsored links
源码文件列表
温馨提示: 点击源码文件名可预览文件内容哦 ^_^名称 | 大小 | 修改日期 |
---|---|---|
/ShutdownComputer/ | 0 Bytes | 2009-06-07 23:36:32 |
/ShutdownComputer/resource.h | 969 Bytes | 2009-05-08 14:04:44 |
/ShutdownComputer/Shutdown.cpp | 1.52 KB | 2009-06-07 23:33:40 |
/ShutdownComputer/Shutdown.h | 203 Bytes | 2009-05-08 07:51:02 |
/ShutdownComputer/ShutdownComputer.cpp | 2.15 KB | 2009-05-07 20:14:56 |
/ShutdownComputer/ShutdownComputer.h | 1.40 KB | 2009-05-07 20:14:56 |
/ShutdownComputer/ShutdownComputer.rc | 5.58 KB | 2009-05-08 14:07:34 |
/ShutdownComputer/ShutdownComputer.sln | 897 Bytes | 2009-06-07 23:26:14 |
/ShutdownComputer/ShutdownComputer.suo | 10.50 KB | 2009-06-07 23:35:26 |
/ShutdownComputer/ShutdownComputer.vcproj | 8.09 KB | 2009-06-07 23:26:12 |
/ShutdownComputer/ShutdownComputerDlg.cpp | 5.58 KB | 2009-06-07 23:30:38 |
/ShutdownComputer/ShutdownComputerDlg.h | 1.70 KB | 2009-06-07 23:29:44 |
/ShutdownComputer/StdAfx.cpp | 218 Bytes | 2009-05-07 20:14:56 |
/ShutdownComputer/StdAfx.h | 1.07 KB | 2009-05-07 20:57:54 |
/ShutdownComputer/Debug/ | 0 Bytes | 2009-06-07 23:35:38 |
/ShutdownComputer/Release/ | 0 Bytes | 2009-06-07 23:35:32 |
/ShutdownComputer/res/ | 0 Bytes | 2009-05-08 14:04:26 |
/ShutdownComputer/res/bitmap1.bmp | 1.24 KB | 2009-05-08 11:19:52 |
/ShutdownComputer/res/lock.ico | 51.44 KB | 2009-05-08 14:04:26 |
/ShutdownComputer/res/me1.bmp | 334.74 KB | 2009-05-08 11:21:56 |
/ShutdownComputer/res/ShutdownComputer.ico | 1.05 KB | 2009-05-07 20:14:56 |
/ShutdownComputer/res/ShutdownComputer.rc2 | 408 Bytes | 2009-05-07 20:14:56 |
Sponsored links