重启电脑代码(转载)
来源:互联网 发布:购买一级域名 编辑:程序博客网 时间:2024/06/03 16:19
Shutting Down
You can use the ExitWindowsEx function to shut down the system. Shutting down flushes file buffers to disk and brings the system to a condition in which it is safe to turn off the computer.
The following example enables the SE_SHUTDOWN_NAME privilege and then shuts down the system.
BOOL MySystemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
return FALSE;
return TRUE;
}
For more information about setting security privileges, see Privileges.
You can use the ExitWindowsEx function to shut down the system. Shutting down flushes file buffers to disk and brings the system to a condition in which it is safe to turn off the computer.
The following example enables the SE_SHUTDOWN_NAME privilege and then shuts down the system.
BOOL MySystemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
return FALSE;
return TRUE;
}
For more information about setting security privileges, see Privileges.
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1238126
- 重启电脑代码(转载)
- 重启电脑代码(转载)
- 重启电脑代码(转载)
- VC---强制重启电脑的代码
- cmd重启电脑代码和方法
- 逐步解决电脑重启(一)
- 电脑重启故障
- 电脑自动重启
- 电脑自动重启
- 重启电脑
- php代码重构那些事(转载)
- 电脑重启故障解析
- 电脑自动重启故障
- 电脑重启故障解析
- 电脑重启的原因
- 重启电脑的应用程序
- 让电脑无限重启
- 电脑关机与重启
- tomcat运行一段时间后,页面打开变得很慢或空白,什么原因?
- JavaScript解析XML实现两级级联下拉列表
- 数据库基本操作
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误
- CScrollBar的困惑
- 重启电脑代码(转载)
- ultraedit 增加 启动和关闭tomcat命令
- 自己封装socket
- 学MFC有感
- 边框大小跟随iframe内容的高度或者宽度
- AIX5L上安装和配置CVS全攻略
- Tomcat全攻略
- Oracle10gR2的ORA-06512 OLAP错误(转eygle)
- [资源收集]大量程序员学习视频教程