从 Windows 7 通过 Process.GetProcesses(string) 读取进程信息时出现异常
我在使用已建立的生产 .NET2 服务时遇到问题。该服务从各种目标计算机收集进程信息和日志文件。它在 80 个站点上运行没有问题;主要在 Windows 2000、Windows XP 和 Windows 2003 上。
现在,针对 Windows 7 目标运行时,只要服务尝试读取进程信息,就会发生异常。
代码如下所示:
Process[] procs = System.Diagnostics.Process.GetProcesses("10.11.12.13");
信息:目标计算机响应 ping,并且目标计算机和服务计算机上都存在“adminUser”凭据。
异常信息:
ex {“无法连接到远程计算机。”} System.Exception {System.InvalidOperationException} [System.InvalidOperationException] {“无法连接到远程计算机。”} System.InvalidOperationException
数据 {System.Collections。 ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
InnerException {“无法获取来自性能计数器的进程信息。"} System.Exception {System.InvalidOperationException} [System.InvalidOperationException] {"无法从性能计数器获取进程信息。"} System.InvalidOperationException
数据 {System.Collections.ListDictionaryInternal} System.Collections。 IDictionary {System.Collections.ListDictionaryInternal}
InnerException {“找不到网络路径”} System.Exception {System.ComponentModel.Win32Exception}
消息“无法从性能计数器获取进程信息。”字符串
源“系统”字符串
StackTrace“位于System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLiblibrary)\r\n位于System.Diagnostics.NtProcessManager.GetProcessInfos(String machineName,Boolean isRemoteMachine)”字符串
TargetSite {System.Diagnostics.ProcessInfo [] GetProcessInfos (系统.诊断.PerformanceCounterLib)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
消息“无法连接到远程计算机。” 为了解决此问题
,我禁用了目标计算机上的 Windows 防火墙,但没有效果。有人有什么想法吗?
如果有人对我应该尝试哪些步骤和顺序有任何建议,我非常感谢您的帮助。
更新:我从监控计算机执行了“tasklist”命令,传递参数来查询远程(目标)计算机,并且我能够看到我无法以编程方式获取的相同类型的进程信息...
该命令看起来像:
tasklist /s 10.11.12.13
返回的信息看起来像:
...
notepad.exe 672 1 4,916 K
...
那么,为什么.NET看不到进程信息???
I'm having trouble with an established production .NET2 service. The service collects process information and log files from various target computers. It runs at 80 sites without issue; mostly on Windows 2000, Windows XP, and Windows 2003.
Now, running against a Windows 7 target, an exception happens whenever the service attempts to read process information.
The code looks like:
Process[] procs = System.Diagnostics.Process.GetProcesses("10.11.12.13");
Info: The target computer responds to ping and the "adminUser" credentials exist on both the target computer and the service computer.
Exception information:
ex {"Couldn't connect to remote machine."} System.Exception {System.InvalidOperationException} [System.InvalidOperationException] {"Couldn't connect to remote machine."} System.InvalidOperationException
Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
InnerException {"Couldn't get process information from performance counter."} System.Exception {System.InvalidOperationException} [System.InvalidOperationException] {"Couldn't get process information from performance counter."} System.InvalidOperationException
Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
InnerException {"The network path was not found"} System.Exception {System.ComponentModel.Win32Exception}
Message "Couldn't get process information from performance counter." string
Source "System" string
StackTrace " at System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLiblibrary)\r\n at System.Diagnostics.NtProcessManager.GetProcessInfos(String machineName, Boolean isRemoteMachine)" string
TargetSite {System.Diagnostics.ProcessInfo[] GetProcessInfos(System.Diagnostics.PerformanceCounterLib)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
Message "Couldn't connect to remote machine." string
To troubleshoot this I disabled the Windows Firewall on the target computer, to no avail. Anyone have any ideas?
If anyone has any suggestions as to which steps and in what order I should be trying I am very appreciative for the assistance.
Update: I executed a "tasklist" command from the monitoring computer, passing the arguments to query the remote (target) computer and I was able to see the same type of process information that I am not able to get programmatically...
The command looked like:
tasklist /s 10.11.12.13
The returned information looked like:
...
notepad.exe 672 1 4,916 K
...
So, why can't .NET see the process information???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原来问题是“远程注册表”服务没有在目标计算机上运行!
这就解释了为什么攻击防火墙没有效果。感谢所有提供帮助的人。
Turns out the problem was that the "Remote Registry" service was not running on the target computer!
This explains why whacking the firewall had no effect. Thanks to everyone who offered assistance.
是的,尝试将实际的机器名称(而不是 IP 地址)传递给函数:
您可以在命令提示符下键入 ipconfig /all 并查找“主机名”以了解机器的名称。
Yes, try passing the actual machine name (not the ip address) to the function:
You can type
ipconfig /all
at the command prompt and look for "Host Name" to know the machine's name.