Connecting to a remote computer using WMI and C #

Hy ... I'm trying to connect to a remote computer using WMI and C #. I get an error: RPC server is unavailable. (Result of HRESULT exception: 0x800706BA). I don't know if this is related to the code, so this is what I use:

serverN = InputText.Text;//serverN=IPAddress userN = userName.Text; passN = passName.Text; if (String.IsNullOrEmpty(serverN)) serverN = "."; ManagementClass manC = new ManagementClass("Win32_LogicalDisk"); string strScope = string.Format(@"\\{0}\root\cimv2", serverN); ConnectionOptions conOpt = new ConnectionOptions(); conOpt.Username = userN; conOpt.Password = passN; manC.Scope = new ManagementScope(strScope, conOpt); 

When I try to get instances from manC, I will catch an exception because RPC is not available. This works locally, so I assume that I need to make some settings on a remote computer (OS: Windows XP sp2). I verified that it allowed remote connections, and I inserted the netsh firewall command to install the RemoteAdmin service on the command line. Do I need to provide a domain name or network identifier? Or is it something else I'm missing?

+1
source share
5 answers

I know this may be late for you, but for others that might stumble on this post: If you are sure that this is not a user rights issue (you know that the folder has permissions) Check what you give as AuthenticationLevel for ConnectionOptions object. I repeated each of them, and for me the only thing that works is the PacketPrivacy option.

 ConnectionOptions conOp = new ConnectionOptions(); conOp.Authentication = System.Management.AuthenticationLevel.PacketPrivacy; 
+3
source

You may need more information about your setup. Are both computers in the same domain?

You can start by testing if WMI works before trying it in C #. Try the following from the command line to see if this works.

wmic /node: path Win32_logicaldisk

wmic also has a / user option, which you can use to verify with your username and password.

You can try changing the authentication and impersonation property to ConnectionOptions . This often changes from medium to medium and can lead to a connection failure.

0
source

Don't seem rude, but: are you sure the value in InputText.Text is correct? One easy way to get "RPC server unavailable" is to provide the wrong name for the server. It might be worth considering the value of "scope" in the debugger after the line. Format call.

BTW I assume this is just a typo that you create and initialize a string called "scope", but passing a variable named "strScope" to the ManagementScope constructor?

0
source

Sounds like a problem with IMHO permissions. In my experience, you need to configure some explicit security permissions to make remote WMI calls.

Is there a TechNet article that can help: http://technet.microsoft.com/en-us/library/cc787533%28WS.10%29.aspx set the appropriate permissions?

0
source

The code works locally because you are already logged in. Remote WMI connections always require additional security rights. Your first code update should include imersonationLevel: http://msdn.microsoft.com/en-us/library/windows/desktop/aa389288%28v=vs.85%29.aspx

If impersonationLevel is not enough, then your next step should be to specify explicit credentials. This will work. There is another option, but I do not recommend it: โ€œdelegate authorityโ€, which allows such an account to pretend to be some kind of account in the domain.

0
source

Source: https://habr.com/ru/post/1499335/


All Articles