2014-10-12 59 views
2

我嘗試使用下面的代碼來獲取特定進程的進程信息和文件:檢索從遠程的機器

Process[] Process = Process.GetProcessesByName(_ProcessName, _Ip); 

_Ip爲「127.0.0.1」,過程被成功取出。 當_Ip代表遠程計算機時,會出現以下異常:

System.InvalidOperationException occurred 
    HResult=-2146233079 
    Message=Couldn't connect to remote machine. 
    Source=System 
    StackTrace: 
     at System.Diagnostics.NtProcessManager.GetProcessInfos(String machineName, Boolean isRemoteMachine) 
     at System.Diagnostics.ProcessManager.GetProcessInfos(String machineName) 
     at System.Diagnostics.Process.GetProcesses(String machineName) 
     at System.Diagnostics.Process.GetProcessesByName(String processName, String machineName) 
     at ToisSimulator.ToisResultsCollector.CollectResults() in d:\PI2\ThirdParty\TCC_New\TccMediator\ToisSimulator\ToisResultsCollector.cs:line 101 
    InnerException: System.InvalidOperationException 
     HResult=-2146233079 
     Message=Couldn't get process information from performance counter. 
     Source=System 
     StackTrace: 
      at System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib library) 
      at System.Diagnostics.NtProcessManager.GetProcessInfos(String machineName, Boolean isRemoteMachine) 
     InnerException: System.ComponentModel.Win32Exception 
      HResult=-2147467259 
      Message=Access is denied 
      Source=System 
      ErrorCode=-2147467259 
      NativeErrorCode=5 
      StackTrace: 
       at System.Diagnostics.PerformanceMonitor.Init() 
       at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item) 
       at System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib library) 
      InnerException: 

我試着做到以下幾點:

  1. 坪兩個機器之間 - 成功

  2. 取消防火牆在遠程機器

  3. 啓用並啓動「遠程註冊」服務在兩臺機器上

檢索過程的目的是要找到它的目錄路徑和讀取使用下面的代碼行日誌位於該目錄下的文件:

FileStream fStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 

回答

2

希望你有試過Process Information on Remote Computer 。 它說正確的方法是有WMI

此鏈接有一個很好的例子,它使用System.Management連接到遠程系統並獲取進程的詳細信息。