我正在编写一个控制另一台计算机的测试应用程序.通过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); } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。