2010-07-19 65 views
4

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

我想以下的:

1)I要么执行ping该计算机,或者
2)有一个共同的驱动器的思想,如果能够访问共享驱动器,或
3)书写一个小服务,我可以沟通

有没有不同/更好的方法?

马克

回答

0

我有你确实遇到的问题,我发现写一个自定义服务是最有用的。 (我实际上需要知道一台无头机器何时准备好接受连接的远程桌面服务,我写的程序实际上会在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); 
     } 
    } 
} 
+0

只是好奇:你为什么不,在那种情况下,只要查询RDP端口。如果你收到一个答案,它是由 – Abel 2010-07-19 21:47:53

+0

,所以我不?。需要不断点击连接以查看它何时准备就绪当我听到提示音时,它会提醒我启动mstsc并连接。 – 2010-07-19 21:50:56

+0

似乎开发服务可能是最好的方法,但我可能会依赖于作为用户* ma的共享文件夹y *需要登录才能运行某些测试软件,除非它在没有用户登录的情况下运行。我仍然需要查看测试软件是否会在没有用户登录的情况下运行。在任何一种情况下,我都可以通过服务检查来查看用户是否已登录,然后将信号发送回控制器PC以开始测试。我选择了Scott的答案,因为他非常友好,为我的事业提供源代码。 – lordhog 2010-07-23 01:04:12

1

这一切都取决于你认为什么“完成启动过程和正常运行”。例如,如果你所关心的只是网卡初始化的那一刻,ping就可能是好的(只要ECHO端口没有关闭)。

A股并不是一个好主意,因为它们通常只有在用户登录时才可用,视情况而定,情况可能并非如此。但即使如果你改变了配置或者认定它是一个安全漏洞来打开一个共享呢?

如果您想要播放它,或者您只需要等到全部服务已经开始,那么您应该考虑第三个选项。这是最容易做到的。让它监听端口80并从IIS运行。当被查询时,它可以回答机器的一些细节。这也会给你最大的灵活性。使用IIS可以帮助您不必编写自己的服务,并使其安装和配置变得简单。

如果IIS不是一个选项,您当然可以考虑编写自己的服务。这并不难,但它需要你编写代码来自己听某些端口。

相关问题