1

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?

Sierra313
  • 75
  • 1
  • 2
  • 7

5 Answers5

3

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;
0

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

If impersonationLevel isn't enough, then your next step should be to specify explicit credentials. That will work. There is one more option but I don't recommend it: "delegate for authority", which allows such an account to pretend to be any account on the domain.

Lizz
  • 1,442
  • 5
  • 25
  • 51
0

Probably need more information on your setup. Are both computers on the same domain?

You could start by testing if the WMI is working before trying it in C#. Try the following from a command prompt to see if that works.

wmic /node: path Win32_logicaldisk

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

You might try changing the Authentication and Impersonation property on the ConnectionOptions. This often changes from environment to environment and can cause the connection to fail.

Naraen
  • 3,240
  • 2
  • 22
  • 20
  • Sorry for my late reply. I have tried the program in a different network environment (no domain set), so on the remote computers I set remote access, Windows firewall and antivirus exeptions and another problem came up: error 0x80070005 access denied. Searching the net I found out that it could be a DCOM settings problem, so tried to edit limits in COM Security for remote launch and remote activation. But still no success, anyway thanks because you took the time to think about it. – Sierra313 Apr 05 '11 at 21:14
0

Not to seem rude but: are you sure the value in InputText.Text is correct? One easy way to get "The RPC server is unavailable" is to supply a bad name for the server. It might be worth examining the value of 'scope' in the debugger after the string.Format call.

BTW I assume it's just a typo that you are creating and initialising a string called 'scope' but passing a variable called 'strScope'to the ManagementScope constructor?

Frank Boyne
  • 4,400
  • 23
  • 30
  • Thank you for your advice. You are right it is a typo there and I have corrected it. The server name is correct I checked in debug mode and with the 127.0.0.1 loopback address and it worked. So locally it works. – Sierra313 Apr 05 '11 at 21:16
0

Sounds like a permissions issue IMHO. From my experience, you need to set up some explicit security permissions to make remote WMI calls.

There's a TechNet article which may help: http://technet.microsoft.com/en-us/library/cc787533%28WS.10%29.aspx have you set the appropriate permissions?

RobS
  • 9,382
  • 3
  • 35
  • 63
  • Many thanks for your reply. Definitely I haven’t set the permissions. Is it a problem if in the link it says that “Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2” and I have only XP? And I’m sorry for my ignorance but should I add (in the security dialog box) the “users” that I am going to manage or is it the other way around: they should add my user name and set the permissions for me? – Sierra313 Apr 05 '11 at 21:15