检查用户空闲时间 [英] checking user idle time

查看:94
本文介绍了检查用户空闲时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个应用程序或Web服务,以检查用户RDP-TCP会话是否空闲,以及是否空闲-关闭另一个应用程序.

但是我不知道在哪里可以找到空闲时间. "Windows任务管理器"没有显示空闲时间,但是远程桌面服务管理器"却显示了.

所以我的问题是

i need to write an application or web service, that checks if users RDP-TCP session is idle, and if its idle - close another application.

but i cannot figure out where to find the idle-time -> "windows task manager" does not show an idle time, but "remote desktop services manager" does.

so my question is

does anybody know where i can find out if the logged on users are idle or not?

推荐答案

粗心回答我自己的问题吗? cmd +查询用户{username}"的输出是
用户名-会话名-ID-状态-空闲时间-登录时间
to rudely answer my own question -> cmd + "query user {username}" the output is
Username - Sessionname - ID - State - Idle Time - Logon Time


如果RDP会话在空闲时被锁定,则可以使用以下逻辑进行检查.
如何在系统锁定后将系统音量静音 [ ^ ]
If the RDP session get''s locked on idle then you can check using following logic.
How to mute the system volume after system lock[^]


我实际上找到了另一种效果很好的解决方案-使用
I actually found another solution, that works quite well - using Cassia

ITerminalServicesManager manager = new TerminalServicesManager();
            using (ITerminalServer server = manager.GetLocalServer())
            {
                server.Open();
                foreach (ITerminalServicesSession session in                    server.GetSessions())
                { 
                    NTAccount account = session.UserAccount;
                    if (session.IdleTime > minutes && account != null && account.ToString().Contains("admin") == false)
                    {

                        listBox1.Items.Add(session.UserAccount + " " + DateTime.Now.ToString());
                        session.Disconnect();
                        Settings.Default.amount++;
                        Settings.Default.Save();
                        label1.Text = "Accounts disconnected: " + Settings.Default.amount.ToString();
                    }
                    else { }
                }
            
            }


这篇关于检查用户空闲时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆