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:
我試着做到以下幾點:
坪兩個機器之間 - 成功
取消防火牆在遠程機器
啓用並啓動「遠程註冊」服務在兩臺機器上
檢索過程的目的是要找到它的目錄路徑和讀取使用下面的代碼行日誌位於該目錄下的文件:
FileStream fStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);