windows 查看给定计算机上的活动远程桌面连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9585402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:19:10  来源:igfitidea点击:

View the active remote desktop connection on a given computer

windowsrdp

提问by d--b

I am looking for a tool to know if a given computer on the local network is being remotely accessed by a user or not and ideally I'd like to know who that user is. In my company, we share virtual machines and we keep have to ask members in the team if they use any remote computer. I'd like to have some kind of dashboard that can tell me what computer is being used, and what computer is free.

我正在寻找一种工具来了解本地网络上的给定计算机是否被用户远程访问,理想情况下我想知道该用户是谁。在我的公司,我们共享虚拟机,我们必须不断询问团队成员是否使用任何远程计算机。我想要某种仪表板,可以告诉我正在使用什么计算机,什么计算机是免费的。

I am happy to use any kind of commercial solution that would require the install of services on each of the machines that need to be monitored or things like that.

我很乐意使用任何类型的商业解决方案,这些解决方案需要在每台需要监控的机器上安装服务或类似的东西。

回答by jeff

The below is made easier if you're querying from a Windows client joined to the same domain as the system you are querying, and may require certain rights above and beyond a standard domain user. If you run into authentication/permission issues, that would be the first thing I'd check.

如果您从加入到与您查询的系统相同的域的 Windows 客户端进行查询,并且可能需要超出标准域用户的某些权限,则下面的操作会变得更容易。如果您遇到身份验证/权限问题,那将是我要检查的第一件事。

There is a tool available at least as far back as Windows XP called "qwinsta". Later versions of Windows have both qwinsta and "query session".

至少早在 Windows XP 中就有一个名为“qwinsta”的工具可用。Windows 的更高版本同时具有 qwinsta 和“查询会话”。

qwinsta /server:computer01
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
                   administrator             2  Disc    rdpwd

That shows user "administrator" logged in but disconnected. Since in this example computer01 is a Windows Server 2003 system with the default "administration" RDP license, there's a second session listening for someone to connect.

这显示用户“管理员”已登录但已断开连接。由于在此示例中,computer01 是具有默认“管理”RDP 许可证的 Windows Server 2003 系统,因此有第二个会话侦听某人的连接。

Running the same command again after connecting to that previously disconnected session looks like this:

连接到先前断开连接的会话后再次运行相同的命令如下所示:

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
[unchanged output removed]
 rdp-tcp#25        administrator             2  Active  rdpwd

This is enough to answer "is someone currently active via RDP", and if you're using individual usernames, it should answer the "who" as well. If you're all using "testuser" or "administrator" or something, you'll probably want to know the answer to "from what client", and that is not given above.

这足以回答“当前是否有人通过 RDP 处于活动状态”,如果您使用个人用户名,它也应该回答“谁”。如果你们都在使用“testuser”或“administrator”之类的东西,你可能想知道“来自哪个客户端”的答案,而上面没有给出。

The above gives a quick basic answer without needing additional tools. For more detailed information, you might look at the cassia libraryor PSTerminalServices(built on cassia). See some of the answers in this questionfor more detail.

以上给出了一个快速的基本答案,不需要额外的工具。有关更多详细信息,您可以查看cassia 库PSTerminalServices(基于 cassia)。有关更多详细信息,请参阅此问题中的一些答案。

My first thought on this was to use Sysinternals tools such as PsLoggedOnor LogonSessions. I then found reference to the previously-unknown-to-me qwinsta and rwinsta tools in this blog post from 2003.

我对此的第一个想法是使用 Sysinternals 工具,例如PsLoggedOnLogonSessions。然后,我在2003 年的这篇博文中找到了对以前未知的 qwinsta 和 rwinsta 工具的引用。

回答by Alban

You can use a PSModule named PSRdSessions, this module provide some simple funtions

你可以使用一个名为PSRdSessions 的 PSModule,这个模块提供了一些简单的功能

sample of use

使用样本

Get-RdSession -ComputerName Server01.domain.xyz # return [Cassia.Impl.TerminalServicesSession]

for return [hashtable]

返回 [哈希表]

Get-RdSession -ComputerName Server01.domain.xyz | Convert-RdSession # return

for return [pscustomobject]

返回 [pscustomobject]

Get-RdSession -ComputerName Server01.domain.xyz | Convert-RdSession | %{[pscustomobject]$_}

enter image description here

在此处输入图片说明