tags:

views:

889

answers:

3

HI,

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..

If Possible Please help me out regarding the same as im struggling from 2 days and its an urgent issue

+1  A: 

Look at KB875605 ("How to troubleshoot WMI-related issues in Windows XP SP2")

Tomalak
+2  A: 

There are a few steps that you must take in order to successfully leverage WMI connectivity. The basics are you must allow remote management on the target box of course. If you can’t RDP into it, chances are, you can’t remote manage anything else. This can also include Windows firewall issues too. Make sure your request can even get in at all.

Next, start simple. Can you even poll for the running processes on that box? Try to output all the running processes on the target box with System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetProcesses("machine-name"). If you can at least get some information on the box then the RPC message you are getting has to do with incorrect arguments being passed in, perhaps?

Anyways, I recently wrote a web application that allowed the users to find a server on the LAN and kill a target process there or start a new one. I did it in C# so the code snippet below is just what I used. It's not the best but its working in production right now:

public static class RemoteProcessAccess
{

    public static void KillProcessByProcessID(string NameOfServer, string DomainName, string LogIn, string Password, int processID)
    {
        //#1 The vars for this static method
        #region /// <variables> ...
            string userName;
            string password;
            string machineName;
            string myDomain;
            Hashtable hs = new Hashtable();
            ManagementScope mScope;
            ConnectionOptions cnOptions;
            ManagementObjectSearcher objSearcher;
            ManagementOperationObserver opsObserver;
            ManagementClass manageClass;
            DirectoryEntry entry;
            DirectorySearcher searcher;
            DirectorySearcher userSearcher;
        #endregion

        //#2 Set the basics sent into the method
            machineName = NameOfServer;
            myDomain = DomainName;
            userName = LogIn;
            password = Password;

            cnOptions = new ConnectionOptions();
            cnOptions.Impersonation = ImpersonationLevel.Impersonate;
            cnOptions.EnablePrivileges = true;
            cnOptions.Username = myDomain + "\\" + userName;
            cnOptions.Password = password;

            mScope = new ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", cnOptions);

        //#3 Begin Connection to Remote Box
            mScope.Connect();
            objSearcher = new ManagementObjectSearcher(String.Format("Select * from Win32_Process Where ProcessID = {0}", processID)); 
            opsObserver = new ManagementOperationObserver();
            objSearcher.Scope = mScope;
            string[] sep = { "\n", "\t" };

        //#4 Loop through 
        foreach (ManagementObject obj in objSearcher.Get())
        {
            string caption = obj.GetText(TextFormat.Mof);
            string[] split = caption.Split(sep, StringSplitOptions.RemoveEmptyEntries);

            // Iterate through the splitter
            for (int i = 0; i < split.Length; i++)
            {
                if (split[i].Split('=').Length > 1)
                {
                    string[] procDetails = split[i].Split('=');
                    procDetails[1] = procDetails[1].Replace(@"""", "");
                    procDetails[1] = procDetails[1].Replace(';', ' ');
                    switch (procDetails[0].Trim().ToLower())
                    {
                        //You could look for any of the properties here and do something else,
                        case "processid":
                            int tmpProc = Convert.ToInt32(procDetails[1].ToString());
                            //if the process id equals the one passed in....
                            //(this is redundant since we should have limited the return 
                            //by the query where above, but we're paranoid here

                            if (tmpProc.Equals(processID))
                            {
                                obj.InvokeMethod(opsObserver, "Terminate", null);                                    
                            }
                            break;

                    }//end process ID switch...

                }//end our if statement...

            }//end our for loop...

        }//end our for each loop...



    }//end static method 
}
Ian Patrick Hughes
Are you sure about your RDP comment? I'd expect you need remote admin enabled but not full RDP?
Ed Guiness
:) Good catch. It was worded poorly. It was not that I meant that RDP was required in order to perform this task, but given how the question was asked, I felt that perhaps he was attempting to connect to a box he never would be able to. It seemed like a good yardstick. In effect, if you can RDP, you should be able to do this.
Ian Patrick Hughes
A: 

Thanks for ur reply..... When i connect from Windows Xp t0 Windows Xp it(WMI connection) works fine but if i try to connect from windows Xp to windows 2003 server or vice-versa it"s failing...... It shows the below error...

Server Error in '/' 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:

Line 77: myScope.Options.Authentication = AuthenticationLevel.Packet; Line 78: mySearcher = new ManagementObjectSearcher(myScope, myQuery); Line 79: myScope.Connect(); Line 80: //myQueryCollection = mySearcher.Get(); Line 81:

Source File: D:\Tools Validator\Skywebadmin\Skywebadmin\WebForm6.aspx.cs Line: 79

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) +783 System.Management.ManagementScope.Initialize() +216 System.Management.ManagementScope.Connect() +5 Skywebadmin.WebForm6.Button1_Click(Object sender, EventArgs e) in D:\Tools Validator\Skywebadmin\Skywebadmin\WebForm6.aspx.cs:79 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Please help me out .........