Community discussion forum

WMI Remote connection in c# using ASP.net

  • 9 months ago
    I have an issue regarding WMI connection through asp.net from Computer A(windows 2003 server) to Computer B(Windows XP).. The error is as follows... RPC server is unavailable.. im using c# as follows.... ConnectionOptions options = new ConnectionOptions(); options.Username =username; options.Password = password; string machinename = "*******"; // Read registry of remote machine.... ManagementScope myScope = new ManagementScope("\\\\" + machinename + "\\root\\default", options); myScope.Options.EnablePrivileges = true; myScope.Options.Impersonation = ImpersonationLevel.Impersonate;myScope.Options.Authentication = AuthenticationLevel.Packet; myScope.Connect(); and the error is as follows Server Error in '/Skywebadmin' Application. -------------------------------------------------------------------------------- The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [COMException (0x800706ba): The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)] System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0 System.Management.ManagementScope.InitializeGuts(Object o) +711 System.Management.ManagementScope.Initialize() +162 System.Management.ManagementScope.Connect() +4 sk._Default.Page_Load(Object sender, EventArgs e) +167 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 Please help me out regarding the same as im struggling from 2 days and its an urgent issue
    Post was edited on 29/01/2009 11:03:44 Report abuse
  • 2 months ago

    There are a couple of things you need to do: 1) if you have not prepared the machines for remote WMI connections, here is a great link: http://msdn.microsoft.com/en-us/library/aa389286(VS.85).aspx .aspx) 2) also, you will need to specify the ConnectionOptions.Authority value as NTLMDOMAIN or Kereberos or else it, by default of a null value, points to the workstation on which the ASP worker process runs. Here is a link with those details: http://msdn.microsoft.com/en-us/library/system.management.connectionoptions.authority.aspx 3) Lastly, make sure you add the scope object to the ManagementSearcherObject override when you get to the point of querying. That last one eluded me for a few days.

    I've got some very detailed notes on how I did it on a few blog posts: http://learningpcs.blogspot.com/2009/08/aspnet-wmi-query-preparing-to-connect.html

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!