加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 确定远程计算机已启动并正在运行的最佳方法

发布时间:2020-12-15 21:08:50 所属栏目:百科 来源:网络整理
导读:我正在编写一个控制另一台计算机的测试应用程序.通过RS-232端口(使用C#应用程序从运行 Windows XP SP2的控制计算机)发送命令字符串来启动测试计算机,此时测试计算机将打开电源并启动到Windows XP.我想知道什么是确定该计算机何时完成启动过程并正常运行的最
我正在编写一个控制另一台计算机的测试应用程序.通过RS-232端口(使用C#应用程序从运行 Windows XP SP2的控制计算机)发送命令字符串来启动测试计算机,此时测试计算机将打开电源并启动到Windows XP.我想知道什么是确定该计算机何时完成启动过程并正常运行的最佳方法.

我在考虑以下几点:

1)我想要ping那台电脑,或者
2)拥有共享驱动器,如果能够访问该共享驱动器,或者
3)写一个我可以与之沟通的小型服务

有不同/更好的方法吗?

标记

解决方法

我遇到了你遇到的确切问题,我发现编写自定义服务是最有用的. (我实际上需要知道无头机器何时让远程桌面服务准备好接受连接,我编写的程序实际上在准备好登录时会发出微调.

编辑:如果你感兴趣,我挖出了源代码.

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);
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读