2010-07-19 32 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不是一個選項,您當然可以考慮編寫自己的服務。這並不難,但它需要你編寫代碼來自己聽某些端口。

相關問題