如何远程查询终端服务活动? [英] How can I query teminal services activity remotely?
本文介绍了如何远程查询终端服务活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想查询我们的服务器以查看是否存在断开连接/空闲会话.我知道我可以使用"query.exe",但是我更喜欢从代码中更容易使用的东西.
I want to query our servers to see look for disconnected/idle sessions. I know I can use 'query.exe', but I'd prefer something that's easier to work with from code.
WMI是我的偏爱.
谢谢.
推荐答案
If you are using a .NET language, you might try Cassia. In C#, the code would be:
using System;
using Cassia;
namespace CassiaSample
{
public static class Program
{
public static void Main(string[] args)
{
ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetRemoteServer("server-name"))
{
server.Open();
foreach (ITerminalServicesSession session in server.GetSessions())
{
if ((session.ConnectionState == ConnectionState.Disconnected)
||
(session.ConnectionState == ConnectionState.Active)
&& (session.IdleTime > TimeSpan.FromMinutes(1)))
{
Console.WriteLine("Session {0} (User {1})", session.SessionId, session.UserName);
}
}
}
}
}
}
更新了Cassia 2.0的示例代码.
Updated sample code for Cassia 2.0.
这篇关于如何远程查询终端服务活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文