gpt4 book ai didi

c# - 在C#中记录登录、注销、系统锁定/解锁事件

转载 作者:行者123 更新时间:2023-11-30 15:02:44 25 4
gpt4 key购买 nike

我正在计划开发一个应用程序,它以 Windows(也许是一项服务)启动并静默记录用户的登录、注销和系统锁定/解锁事件。

如果有人能给我一个提示来记录他们的总空闲时间(用户没有执行系统事件的时间),那就太棒了

我正在寻找一个预开发的库或可以帮助我顺利完成项目的东西。

最佳答案

试试下面的代码....

private enum WTS
{
CONSOLE_CONNECT = 1,
CONSOLE_DISCONNECT = 2,
REMOTE_CONNECT = 3,
REMOTE_DISCONNECT = 4,
SESSION_LOGON = 5,
SESSION_LOGOFF = 6,
SESSION_LOCK = 7,
SESSION_UNLOCK = 8,
SESSION_REMOTE_CONTROL = 9
}

protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg) {
case WM_WTSSESSION_CHANGE:
switch (m.WParam.ToInt32) {
case WTS.CONSOLE_CONNECT:
//MessageBox.Show("A session was connected to the console session.");

break;
case WTS.CONSOLE_DISCONNECT:
//MessageBox.Show("A session was disconnected from the console session.");

break;
case WTS.REMOTE_CONNECT:
break;
//MessageBox.Show("A session was connected to the remote session.");
case WTS.REMOTE_DISCONNECT:
break;
//MessageBox.Show("A session was disconnected from the remote session.");
case WTS.SESSION_LOGON:

break;
//MessageBox.Show("A user has logged on to the session.")
case WTS.SESSION_LOGOFF:
//MessageBox.Show("A user has logged off the session.");

break;
case WTS.SESSION_LOCK:
//MessageBox.Show("A session has been locked.")

break;
case WTS.SESSION_UNLOCK:
//MessageBox.Show("A session has been unlocked.")

break;
case WTS.SESSION_REMOTE_CONTROL:
MessageBox.Show("A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric.");
break;
}

break;
}

base.WndProc(m);
}

关于c# - 在C#中记录登录、注销、系统锁定/解锁事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12457852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com