我正在尝试编写C#代码来远程访问计算机(XP SP2)以查明进程是否正在运行。 除了过去几天我读到的内容,我对性能指标的了解不多,但是这里是我的问题:
对于故障排除,当我使用psList( pslist \\target -u user -p pass
)访问目标计算机时,出现此错误:
Cannot connect to remote registry on <computer> Access is denied. Failed to take process snapshot on <computer> Make sure that Remote Registy service is running on the remote system, that you have firewall ports allow RPC access, and your account has read access the following key on the remote system: HKLM\Software\Microsoft\Windows NT\CurrentVersion\perflib
当我使用pslist作为pipe理员时,我得到了同样的错误,除了它说The network path was not found
而不是Access is denied
。 我得到这是否我以我的正常帐户“以pipe理员身份运行”,或者如果我实际login到我的pipe理员帐户并从那里运行该命令。
远程registry正在目标计算机上运行。
当我使用sc查询( sc \\target query
)作为pipe理员时,我得到这个错误:
[SC] OpenSCManager FAILED 5: Access is Denied
当我的这部分C#代码运行时, Process[] targetProcess = Process.GetProcessesByName(string process, string ip);
(我在这里使用一个IP地址作为我的string,而不是一个计算机名),我得到这个罗嗦的错误:
System.InvalidOperationException:无法连接到远程计算机。 —> System.InvalidOperationException:无法从性能计数器获取进程信息。 —> System.ComponentModel.Win32Exception:System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item)在System.Diagnostics.PerformanceMonitor.Init()System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib库)上找不到networkingpath—内部exception堆栈跟踪结束—
System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib库)在System.Diagnostics.NtProcessManager.GetProcessInfos(stringmachineName,布尔isRemoteMachine)—内部exception堆栈跟踪结束—
System.Diagnostics.NotProcessManager.GetProcessInfos(String machineName,Boolean isRemoteMachine)在System.Diagnostics.ProcessManager.GetProcessInfos(String machineName)在System.Diagnostics.Process.GetProcesses(stringmachineName)在System.Diagnostics.Process.GetProcessesByName(String processName ,stringmachineName)在(方法名)在c:(path名):第132行
从我有限的知识来看,performance指标似乎运作良好,但我仍然得到这些错误,表明他们是问题。 为什么我会收到这些错误?
考虑到这个答案有多简单,我觉得有点愚蠢。 我一直在为这个和类似的问题挣扎数周。 一位同事发现,碰巧在批处理和C#中都已经有了答案。
原来这是一个权限问题,而不是性能计数器。 哪个回答了我的大部分问题。 这个命令解决了sc query
问题:
NET USE \\target\IPC$ /u:user pass
我不知道IPC $的份额。 插入之后,我可以自由地在目标上使用sc query
, query process
和其他远程命令。 有趣的是,尽pipe我仍然不能使用psList
。 我不需要它,虽然没有看到它。
C#代码很长 – 当我有代码的时候,我会把它放在这里。 基本上,它所做的只是创build一个Process对象,并将其插入上面的命令行代码中。 之后,我可以运行我的C#代码的其余部分来从目标运行进程。