我正在研究 WMI。我想访问远程系统信息。以下代码适用于环回或本地主机,但是当我尝试访问远程机器时,它显示以下异常错误:
访问被拒绝。(来自 HRESULT:0X8005(E_ACCESSDENIED) 的异常)
在 2 个系统之间使用 switch 时。
和
RPC 服务器不可用。(来自 HRESULT 的异常:0x800706BA)
当两个系统直接连接时。
两个系统上的操作系统:Windows Service Pack 2。
防火墙 = 被阻止。
远程过程服务 = 正在运行。
工具:.NET Visual Studio 2008 C#
代码:
try
{
ConnectionOptions _Options = new ConnectionOptions();
ManagementPath _Path = new ManagementPath(s);
ManagementScope _Scope = new ManagementScope(_Path, _Options);
_Scope.Connect();
ManagementObjectSearcher srcd = new ManagementObjectSearcher("select * from Win32_DisplayConfiguration");
foreach (ManagementObject obj in srcd.Get())
{
//listBox5.Items.Add(obj.Properties.ToString());
foreach (PropertyData aProperty in obj.Properties)
{
listBox1.Items.Add(aProperty.Name.ToString() + " : " + aProperty.Value);
} …
Run Code Online (Sandbox Code Playgroud)