为什么我用ExitWindowsEx( EWX_SHUTDOWN | EWX_FORCE, 0 );强制关机后,再启动时会显示白屏,要重置桌面,有时还会重新scandisk,就好象非法关机一样,而且有时还关不掉电源,只是把显示器关黑了。
解决方案 »
- 多线程单链表
- com为什么不允许接口类中 (函数重载)?
- 关于 资源拖拽 (DoDragDrop中的第三个参数)问题
- 完成端口
- 哪里可以下载英文版的《MFC Internals》?请指教。谢谢!
- 我建了一些非模态对话框,可是它们总是浮在我的主视图之上,影响了主视图的操作,有没有方法解决这个问题?
- 怎样查询多个数据库的记录, 马上给分,因为我也很急
- 如何写出在IE上内嵌的如金山词霸、flashget等的工具栏
- 求助:把24位BMP真彩图变成灰度图,以BMP的格式保存在硬盘上
- (急)vc编写有MFC支持的控制台程序,但在程序中要用到ADO,请问我初始化变量时候出错了!
- Link错误,为什么?看看
- 我在WIN98中用CreateProcess重定向到管道的控制台文本无法获得?
Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. From re
Windows NT: To shut down or restart the system, the calling process must use theAdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information about security privileges, seePrivileges. it means void CShutdownDlg::OnButton1()
{
HANDLE hdl;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hdl);
PTOKEN_PRIVILEGES ptoken = (PTOKEN_PRIVILEGES) new BYTE[sizeof(DWORD) +
sizeof(LUID_AND_ATTRIBUTES)];
ptoken->PrivilegeCount = 1;
LUID uid;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &uid); ptoken->Privileges[0].Luid = uid;
ptoken->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hdl, FALSE, ptoken, 0, NULL, NULL); //向进程表内写入数据
CloseHandle(hdl);
delete [](BYTE *)ptoken;
ExitWindowsEx(EWX_FORCE|EWX_POWEROFF,0);
}
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
AfxMessageBox("OpenProcessToken");
// 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);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
AfxMessageBox("AdjustTokenPrivileges");
// Shut down the system and force all applications to close.
ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0);
如果是win2000的话当然需要楼上的那种了
ExitWindowsEx(EWX_POWEROFF|EWX_FORCE,0);
Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. If the system supports the power-off feature, the power is also turned off. EWX_POWEROFF
Shuts down the system and turns off the power. The system must support the power-off feature. EWX_FORCE
Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
最好不要用EWX_FORCE,因为不会给应用程序发消息,容易丢失数据。
另外,楼上说的关机补丁可能很重要。