I'm trying to connect to other network using my pc but im getting error
(System.Runtime.InteropServices.COMException: 'The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)')
However, It's only working if I connect to my pc itself. Is there any approach aside from this process because I cant even figure what's the error if it's like firewall,my codes or my anti-virus etc.
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());
}
}
I think you should read through this
Connecting to WMI Remotely with C#
Create a ManagementScope
object, using the name of the computer and the WMI path, and connect to your target with a call to ManagementScope.Connect()
.
If you connect to a remote computer in a different domain or using a different user name and password, then you must use a ConnectionOptions
object in the call to the ManagementScope
.
The
ConnectionOptions
contains properties for describing the Authentication, Impersonation, username, password, and other connection options.
Exmaple
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);
...
Generally speaking, it is recommended that you set your Impersonation level to Impersonate unless explicitly needed otherwise
Assuming you have the correct credentials, i think this will turn out to be a firewall issue, or a windows setting on the remote computer.
Id apply the following firewall rules first and work backwards. Or for a test completely disable firewalls on the target machine
COM+ Network Access (DCOM-In)
Remote Event Log Management (NP-In)
Remote Event Log Management (RPC)
Remote Event Log Management (RPC-EPMAP)
Windows Management Instrumentation (ASync-In)
Windows Management Instrumentation (DCOM-In)
Windows Management Instrumentation (WMI-In)
Additional reading
Connecting to WMI Remotely with C#
Disclaimer : You will have to read about these topics and work out what you need in your situation.
User contributions licensed under CC BY-SA 3.0