读书人

有没有达人知道什么方法获得的关机事件

发布时间: 2012-01-18 00:23:26 作者: rapoo

有没有达人知道什么方法获得的关机事件是关机还是重起事件。
有没有达人知道什么方法获得的关机事件是关机还是重起事件。

[解决办法]
为什么需要获取这个,是否可以通过一些别的方式
[解决办法]
hook
[解决办法]
http://www.cnblogs.com/daoluanxiaozi/archive/2011/10/12/2208932.html
[解决办法]
我很好奇,都关机了,你还想做什么操作?判别了有什么用?
难道是开机启动?开机启动不是可以在开机中处理么?
[解决办法]

探讨
有没有达人知道什么方法获得的关机事件是关机还是重起事件。

[解决办法]
好奇中。。。
[解决办法]
C/C++ code
    static HANDLE hToken;    static TOKEN_PRIVILEGES tp;    static LUID luid;    OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);    LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);    tp.PrivilegeCount = 1;    tp.Privileges[0].Luid = luid;    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;    AdjustTokenPrivileges(hToken,FALSE,&tp,sizeof(TOKEN_PRIVILEGES),NULL,NULL);    ExitWindowsEx(EWX_POWEROFF,0);    //关机    ExitWindowsEx(EWX_REBOOT,0);       //重启
[解决办法]
关机事件是怎么获得的啊
楼主指导指导
[解决办法]
探讨

C/C++ code

static HANDLE hToken;
static TOKEN_PRIVILEGES tp;
static LUID luid;
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);

LookupPr……

[解决办法]
依MSDN解释,WM_QUERYENDSESSION 确实无法区分。
可以读取注册表
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shutdown Setting" 下DWORD值,来确定用户在关机对话框时的选择
如果没有此键,可新建一个,记住类型为DWORD。

官方对此值解释如下:
This entry stores the setting selected most recently from the list on the Shut Down Windows dialog box. This setting is displayed as the default the next time the dialog box appears.
0x1
Log off. Ends the session, leaving the computer running on full power.
0x2
Shut down. Ends the session and shuts down Windows 2000 so that the power can be turned off safely.
0x4
Restart. Ends the session, shuts down Windows 2000, and starts Windows 2000 again.

读书人网 >VC/MFC

热点推荐