gpt4 book ai didi

c# - 从远程机器检索进程信息和文件

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:49 25 4
gpt4 key购买 nike

我正在尝试使用以下代码检索特定进程:

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. 两台机器之间Ping – 成功

  2. 在远程机器上取消防火墙

  3. 在两台机器上启用并启动“Remote Registry”服务

检索进程的目的是找到它的目录路径并使用以下代码行读取位于该目录中的日志文件:

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

最佳答案

希望你已经尝试过Process Information on Remote Computer.它说正确的方法是使用 WMI

此链接有很好的示例,它使用 System.Management 连接到远程系统并获取进程详细信息。

关于c# - 从远程机器检索进程信息和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26326234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com