I am trying to access EC2 machines remotely to get some info using C#. I wrote code as below:-

ConnectionOptions options = new ConnectionOptions
Username = serverspace.ServerIP + @"\xxxxxx",
Password = "xxxxxxx",
Impersonation = ImpersonationLevel.Impersonate,
EnablePrivileges = true

ManagementScope scope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", serverspace.ServerIP), options);


But an RPC exception is thrown as below:- The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Management.ManagementScope.InitializeGuts(Object o) at System.Management.ManagementScope.Initialize()

1- Is the problem in the code? 2- Do I need to adjust anything in all machines firewall?

  • Did you ever get this to work? I'm trying the same thing with no luck so far. – Daniel Williams Feb 27 '18 at 0:28
  • Nop, I quit my approach. I wanted to remotely control windows services on machine. – Bassam Gamal Feb 27 '18 at 13:17

RPC firewall ports are documented here:

Service overview and network port requirements for Windows
-Remote Procedure Call (RPC):

System service name: RpcSs  
Application protocol    Protocol    Ports  
RPC TCP 135  
RPC over HTTPS  TCP 593  
NetBIOS Datagram Service    UDP 138  
NetBIOS Name Resolution UDP 137  
NetBIOS Session Service TCP 139  
SMB TCP 445  

Additionally, you need the "high ports" range 49152 through 65535.

  • So this is thing to adjust for all EC2 instances' firewall or I've to adjust it from Security Group? – Bassam Gamal Apr 23 '13 at 14:22
  • I'm not sure what you mean. RPC and WMI require a truckload of ports to be open in the firewall. If you don't have the firewalls configured appropriately, WMI is not a viable option. – Greg Askew Apr 23 '13 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.