我试图检测用户何时解锁他们的工作站。以下代码尝试使用WTSRegisterSessionNotification()注册窗口以接收会话更改消息。据说在此之后,我可以监听WM_WTSSESSION_CHANGE,它可以包含WTS_SESSION_UNLOCK作为参数。当用户解锁工作站时检测
问题:目前WTSRegisterSessionNotification()总是返回false。
任何人都知道我可以做到这一点?我在Windows 10 btw。
var {remote} = require('electron');
var ffi = require('ffi');
var winctl = require('winctl');
var NOTIFY_FOR_ALL_SESSIONS = 1;
var WM_WTSSESSION_CHANGE = parseInt('0x02B1', 16);
var hwnd = remote.getCurrentWindow().getNativeWindowHandle();
var wtsapi32 = ffi.Library('wtsapi32', {
'WTSRegisterSessionNotification': [ 'bool', [ 'int', 'int' ] ]
});
// Attempt to register
var isregistered = wtsapi32.WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_ALL_SESSIONS);
console.log(isregistered); // <----- RETURNS 0...?
IInspectable recommended GetLastError()。 这不是node-ffi不支持的东西。 https://github.com/node-ffi/node-ffi/issues/261
从[documentation](https://msdn.microsoft.com/en-us/library/aa383841.aspx):*“如果函数成功,则返回值为TRUE,否则为FALSE。* *要获得扩展错误信息,请调用[GetLastError](https://msdn.microsoft.com/en-us/library/ms679360.aspx)。**“* – IInspectable
嗨,感谢您的评论。看起来这不幸的是,当使用node-ffi时,这不是一个选项。我修改了这个问题,只是为了确保。还发现这个:https://github.com/node-ffi/node-ffi/issues/261 –
呵呵。有人甚至去解决问题的麻烦,而且修复程序从未融入到项目中。恐怕这意味着你失明了。也许你可以编写一个简单的C DLL来代表你调用WTSRegisterSessionNotification并返回错误代码? –