c# – 确定远程计算机已启动并正在运行的最佳方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 确定远程计算机已启动并正在运行的最佳方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2077字,纯文字阅读大概需要3分钟。
内容图文
![c# – 确定远程计算机已启动并正在运行的最佳方法](/upload/InfoBanner/zyjiaocheng/769/a0a43c50ccba47f7bd198235f6e7d2a7.jpg)
我正在编写一个控制另一台计算机的测试应用程序.通过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);
}
}
}
内容总结
以上是互联网集市为您收集整理的c# – 确定远程计算机已启动并正在运行的最佳方法全部内容,希望文章能够帮你解决c# – 确定远程计算机已启动并正在运行的最佳方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。