确定远程计算机已启动并运行的最佳方法

发布于 2024-09-11 00:33:05 字数 294 浏览 3 评论 0原文

我正在编写一个控制另一台计算机的测试应用程序。通过 RS-232 端口(从使用 C# 应用程序运行 Windows XP SP2 的控制计算机)发送命令字符串来启动测试计算机,此时测试计算机将开机并引导至 Windows XP。我想知道确定计算机何时完成启动过程并正常运行的最佳方法是什么。

我正在考虑以下问题:

1)我要么正在考虑对那台计算机执行 ping 操作,要么
2) 拥有共享云端硬盘并且能够访问该共享云端硬盘,或者
3)编写一个我可以与之通信的小服务

有不同/更好的方法吗?

标记

I am writing a test application which is controlling another computer. The test computer is started by sending a command string via the RS-232 port (from a control computer running Windows XP SP2 using a C# application), at which time the test computer will power-on and boot into Windows XP. I would like to know what would be the best method to determine when that computer has completed it boot process and running normally.

I was thinking of the following:

1) I was either thinking of pinging that computer, or
2) Have a shared drive and if able to access that shared drive, or
3) Writing a small service which I can communicate with

Is there different/better approach?

Mark

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

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

发布评论

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

评论(2

最终幸福 2024-09-18 00:33:06

这完全取决于您认为“已完成启动过程并正常运行”的情况。。例如,如果您只关心网卡初始化的时刻,则 ping 可能会很好(只要 ECHO 端口未关闭)。

共享不是一个好主意,因为它们通常仅在用户登录时才可用,根据您的情况,情况可能会也可能不会。但即使如此,如果您更改配置或认为开放共享存在安全漏洞怎么办?

如果您想一定要玩它或者您只是需要等到所有服务启动,您应该考虑第三种选择。这是最容易做到的。让它侦听端口 80 并从 IIS 运行。当询问时,它可以回答机器的一些详细信息。这也将为您提供最大的灵活性。使用 IIS 可以帮助您不必编写自己的服务,并使安装和配置变得简单。

如果 IIS 不可行,您当然可以考虑编写自己的服务。做起来并不难,但它需要您自己编写代码来监听某些端口。

It all depends on what you consider "completed its boot process and is running normally". For instance, if all you care is the moment the network card is initialized, pinging might be good (as long as the ECHO port isn't closed).

A share is not a good idea as they generally only become available when a user is logged in, which may or may not be the case depending on your situation. But even if, what if you change the configuration or decide it is a security breach to open up a share?

If you want to play it certain or if you just need to wait until all services have started, you should consider your third option. It's easiest to do. Let it listen on port 80 and run from IIS. When queried, it can answer with some details of the machine. This will also give you the most flexibility. Using IIS helps you for not having to write your own service and makes it trivial to install and configure.

If IIS is not an option, you can of course consider writing your own service. Not that hard to do, but it'll require you to write the code to listen to certain ports yourself.

Saygoodbye 2024-09-18 00:33:06

我遇到了您遇到的确切问题,我发现编写自定义服务是最有用的。 (我实际上需要知道无头计算机何时准备好远程桌面服务来接受连接,我编写的程序实际上在准备登录时会发出小调的 PC 扬声器蜂鸣声。

编辑:我挖出了源代码,以防万一你感兴趣的地方。

using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Threading;

namespace Beeper
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
                { 
                    new Beeper() 
                };
            ServiceBase.Run(ServicesToRun);
        }
    }

    public partial class Beeper : ServiceBase
    {
        public Beeper()
        {
        }

        protected override void OnStart(string[] args)
        {
            if (MainThread != null)
                MainThread.Abort();
            MainThread = new Thread(new ThreadStart(MainLoop));
            MainThread.Start();
        }

        protected override void OnStop()
        {
            if (MainThread != null)
                MainThread.Abort();
        }

        protected void MainLoop()
        {
            try
            {
                //main code here
            }
            catch (ThreadAbortException)
            {
                //Do cleanup code here.
            }
        }

        System.Threading.Thread MainThread;
    }
    [RunInstaller(true)]
    public class BeeperInstaller : Installer
    {
        private ServiceProcessInstaller processInstaller;
        private ServiceInstaller serviceInstaller;
        public BeeperInstaller()
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;
            serviceInstaller.StartType = ServiceStartMode.Automatic;
            serviceInstaller.ServiceName = "MyProgram";
            serviceInstaller.ServicesDependedOn = new string[] { "TermService" }; //Optional, this line makes sure the terminal services is up and running before it starts.
            Installers.Add(serviceInstaller);
            Installers.Add(processInstaller);
        }
    }
}

I had the exact problem you did, I found writing a custom service was the most useful. (I actually needed to know when a headless machine had the Remote Desktop service ready to accept connections, the program I wrote actually beeps the PC speaker a little tune when it is ready to be logged in.

EDIT: I dug up the source in case you where interested.

using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Threading;

namespace Beeper
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
                { 
                    new Beeper() 
                };
            ServiceBase.Run(ServicesToRun);
        }
    }

    public partial class Beeper : ServiceBase
    {
        public Beeper()
        {
        }

        protected override void OnStart(string[] args)
        {
            if (MainThread != null)
                MainThread.Abort();
            MainThread = new Thread(new ThreadStart(MainLoop));
            MainThread.Start();
        }

        protected override void OnStop()
        {
            if (MainThread != null)
                MainThread.Abort();
        }

        protected void MainLoop()
        {
            try
            {
                //main code here
            }
            catch (ThreadAbortException)
            {
                //Do cleanup code here.
            }
        }

        System.Threading.Thread MainThread;
    }
    [RunInstaller(true)]
    public class BeeperInstaller : Installer
    {
        private ServiceProcessInstaller processInstaller;
        private ServiceInstaller serviceInstaller;
        public BeeperInstaller()
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;
            serviceInstaller.StartType = ServiceStartMode.Automatic;
            serviceInstaller.ServiceName = "MyProgram";
            serviceInstaller.ServicesDependedOn = new string[] { "TermService" }; //Optional, this line makes sure the terminal services is up and running before it starts.
            Installers.Add(serviceInstaller);
            Installers.Add(processInstaller);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文