我试图检测用户何时解锁他们的工作站。以下代码尝试使用 WTSRegisterSessionNotification() 注册窗口以接收会话更改消息。据说在此之后我可以收听 WM_WTSSESSION_CHANGE ,它可以包含 WTS_SESSION_UNLOCK 作为参数。
问题:目前 WTSRegisterSessionNotification() 总是返回 false。
有谁知道我怎么能做到这一点?我在 Windows 10 顺便说一句。
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 推荐 GetLastError()。不幸的是,这不是 node-ffi 支持的。 https://github.com/node-ffi/node-ffi/issues/261