如何自动测试与 Windows 2003 服务器的连接?

发布于 2024-08-02 00:33:04 字数 372 浏览 4 评论 0原文

我正在编写一个应用程序来测试与一组 VM Windows 2003 服务器的 RDP 连接。 典型的故障模式是服务器上运行的某些代码陷入循环,从而阻止 RDP 连接以及大多数其他类型的连接。 发生这种情况时,您仍然可以 ping 服务器并且似乎没问题,但您无法执行其他任何操作。

我正在使用 C#、.NET 3.5 和 RDP 版本 6.1——我尝试启动 ActiveX RDP 客户端 (MSTSC..),但这需要人工干预,并且效果不佳。 我在这里找到了另一篇文章,其中有来自 Expert Sexchange 的可能解决方案,但该解决方案使用 Java 和 Net::Telnet 库,而我无权访问该库。

.NET 阵营有什么想法吗?

谢谢, 戴夫

I am writing an app to test RDP connectivity to a bank of VM Windows 2003 servers. The typical failure mode is for some code running on the server to get itself in a loop, preventing RDP connections -- and most any other type of connection, as well. When this happens, you can still ping the server and it seems to be fine, but you cannot do much of anything else.

I am using C#, .NET 3.5 and RDP version 6.1 -- I have tried launching the ActiveX RDP client (MSTSC..) but that requires human intervention and doesn't work very well. I found another post here that has a possible solution from Expert Sexchange, but that solution uses Java and the Net::Telnet library, which I do not have access to.

Any ideas from the .NET camp?

Thanks,
Dave

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虐人心 2024-08-09 00:33:04

您可以使用未记录的 WinStationServerPing API检查与终端服务器的连接。 基本上,如果此功能成功,则意味着终端服务器可用。

这是函数的(Delphi)签名(从 winsta.dll 导出):

function WinStationServerPing(hServer: HANDLE): BOOLEAN; stdcall;

You can use the undocumented WinStationServerPing API to check connectivity to Terminal Server. Basically if this function succeeds it means that Terminal Server is available.

This is the (Delphi) signature of the function (exported from winsta.dll):

function WinStationServerPing(hServer: HANDLE): BOOLEAN; stdcall;
左秋 2024-08-09 00:33:04

使用 TCPClient 尝试连接到3389(或您配置的任何端口)上的服务器如果获得连接,则断开连接并报告成功,如果连接被拒绝则报告失败。

 class Program
    {
       static void Main(string[] args)
        {
            RDPAvailable("someserver", 3389);
        }
        public static bool RDPAvailable(string remoteHost, int port)
        {
            bool available=false;
            try
            {
                TcpClient client = new TcpClient(remoteHost, port);
                client.Close();
                available = true;
            }
            catch (Exception ex)
            {
                //do some logging or whatnot 
            }
            return available;
    }

编辑:一些方便的代码

MsRdpClient51.Server = somServer
MsRdpClient51.UserName = somUserID
MsRdpClient51.Domain = someDomain
MsRdpClient51.AdvancedSettings6.ClearTextPassword = somePassword
MsRdpClient51.Connect

Use a TCPClient to try and connect to the servers on 3389 (or whatever port you are configured for) if you get a connection, disconnect and report success, if the connection is refused report failure.

 class Program
    {
       static void Main(string[] args)
        {
            RDPAvailable("someserver", 3389);
        }
        public static bool RDPAvailable(string remoteHost, int port)
        {
            bool available=false;
            try
            {
                TcpClient client = new TcpClient(remoteHost, port);
                client.Close();
                available = true;
            }
            catch (Exception ex)
            {
                //do some logging or whatnot 
            }
            return available;
    }

EDIT: Some handy code

MsRdpClient51.Server = somServer
MsRdpClient51.UserName = somUserID
MsRdpClient51.Domain = someDomain
MsRdpClient51.AdvancedSettings6.ClearTextPassword = somePassword
MsRdpClient51.Connect
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文