C# – Connect to remote computer using WMI and C#

cwmi

Hy… I am trying to connect to a remote computer using WMI and C#.
I get an error: The RPC server is unavailable. (Exception result HRESULT: 0x800706BA).
I don't know if that is code related so this is what I'm using:

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 catch the exception with the RPC being unavailable.
Locally it works so I'm guessing that I have to make some settings on the remote machine (OS: Windows XP sp2).
I have checked so that it allows remote connections and I have inserted command netsh firewall set service RemoteAdmin into command prompt.
Do I need to set a domain name or a networkid?
Or it is something else I'm missing?

Best Answer

I know it might be late for you, but for others who might stumble on this post: If you're sure it is not a user rights issue (you know the folder has the permissions) Check what you're giving as AuthenticationLevel to the ConnectionOptions object. I iterated through every one of them and for me the only that works is the PacketPrivacy option.

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