如何以编程方式告诉如果终端服务器服务正在运行 [英] How to programmatically tell if the terminal server service is running

查看:165
本文介绍了如何以编程方式告诉如果终端服务器服务正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式告诉如果终端服务正在运行,并且是健康的? 我创建一个.NET控制台应用程序将检查终端服务的计算机列表上运行。

How can I programmatically tell if the terminal services service is running and is healthy? I'm creating a .net console application that will check if terminal services are running on a list of computers.

我可以查看远程注册表项,看看它的启用,但并不意味着它的运行。 我的想法是做一个套接字连接到端口3389,但它并没有被任何该端口上侦听。

I can check the remote registry entry to see if it's enabled, but that doesn't mean it's running. I was thinking of making a socket connection to port 3389, but it doesn't have to be listening on that port either.

有一种优雅的方式来检查呢?

Is there an elegant way to check for this?

问候,

推荐答案

如果你(或,具体而言,应用程序运行用户)有权限的话,你可以远程查询目标设备,以确定的供应链管理在TS服务正在运行。

If you (or, specifically, the user the application runs as) has permission to do so, you could remotely query the SCM of the target machine to determine if the TS service is running.

您应该能够使用System.ServiceProcess.ServiceController.GetServices(字符串机器名)来获取计算机上的所有服务的列表,迭代结果找到终端服务和查询其状态。

You should be able to use System.ServiceProcess.ServiceController.GetServices(string machineName) to get a list of all the services on the computer, iterate the result to find the Terminal Services service and query its status.

这篇关于如何以编程方式告诉如果终端服务器服务正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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