[英]C#: Why I can only connect to my ip address but the other ip address, getting error (WMI)
我正在尝试使用我的PC连接到其他网络,但我收到了错误消息
(System.Runtime.InteropServices.COMException:'RPC服务器不可用。(HRESULT的异常:0x800706BA)')
但是,仅当我连接到PC本身时,它才有效。 除了此过程外,还有什么方法可以解决,因为我什至无法弄清楚如果发生了什么错误,例如防火墙,我的代码或我的防病毒软件等。
private void Form2_Load(object sender, EventArgs e)
{
// remote computer.
ManagementScope scope =
new ManagementScope(
"\\\\172.20.1.50\\root\\cimv2");
scope.Connect();
//Query system for Operating System information
ObjectQuery query = new ObjectQuery(
"SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
// Display the remote computer information
MessageBox.Show(m["csname"].ToString());
}
}
我认为你应该通读
使用计算机的名称和WMI路径创建一个ManagementScope
对象,并通过调用ManagementScope.Connect()
连接到您的目标。
如果连接到其他域中的远程计算机或使用其他用户名和密码,则必须在对ManagementScope
的调用中使用ConnectionOptions
对象。
ConnectionOptions
包含用于描述身份验证,模拟,用户名,密码和其他连接选项的属性。
枫树
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
// options takes more arguments, you need to read up on what you want
ManagementScope scope = new ManagementScope("\\\\FullComputerName\\root\\cimv2", options);
scope.Connect();
ManagementPath path = new ManagementPath("Win32_NetworkAdapterConfiguration");
ObjectGetOptions o = new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
ManagementClass objMC = new ManagementClass(scope, path, o);
...
一般来说,除非明确需要,否则建议您将模拟级别设置为“模拟”
假设您具有正确的凭据,我认为这将是防火墙问题或远程计算机上的Windows设置。
请先应用以下防火墙规则,然后再反向进行。 或进行测试以完全禁用目标计算机上的防火墙
COM +网络访问(DCOM输入)
远程事件日志管理(NP-In)
远程事件日志管理(RPC)
远程事件日志管理(RPC-EPMAP)
Windows管理规范(ASync-In)
Windows管理规范(DCOM-In)
Windows管理规范(WMI-In)
补充阅读
免责声明 :您将必须阅读有关这些主题的信息,并弄清自己所处的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.