locked
WMI "server not found" eror RRS feed

  • Question

  • Hey all,
    I have a winServer 2008 machine. I have created a new local user.
    In order to make him an admin all I have to do is to add it to the "administrators" group. right?
    now, I wrote a c# code that supposed to connect that local user and execute some exe file remotely.

     

     static void Main(string[] args)
      {
    
       string remoteMachine = "HV-BENDA";    
       string sBatFile = string.Empty;
    
       try
       {
         string _cmd = "D:\\LocalUserManagerDLL3.5\\RunDll\\bin\\Debug\\RunDll.exe";
        if (_cmd.Trim() == string.Empty)
        {
         Console.WriteLine("No command entered using default command for test :" + _cmd);
        }
    
        ConnectionOptions connOptions = new ConnectionOptions();
    
      connOptions.Username = "HV-BENDA\test2";
            connOptions.Password = "Pa$$word1";
    
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
            connOptions.EnablePrivileges = true;
    
    
        ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", remoteMachine), connOptions);
        manScope.Connect();
        ObjectGetOptions objectGetOptions = new ObjectGetOptions();
        ManagementPath managementPath = new ManagementPath("Win32_Process");
        ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
        ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
        inParams["CommandLine"] = sBatFile;
        ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
        Console.WriteLine("Creation of the process returned: " + outParams["returnValue"]);
        Console.WriteLine("Process ID: " + outParams["processId"]);
    
       }
       catch (Exception ex)
       {
        Console.WriteLine("Error " + ex.Message);
       }
    }
    
    

     

     

    but the following exception is thrown from the manScope.Connect(); line
    "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"
     
    when I omit
     connOptions.Username = "HV-BENDA\test3";
     connOptions.Password = "1234";
    everything works just fine.This, as I understand, connects with my current user (which is domain admin and not just local admin). So I have tried to use these two lines with my current user credentials- but the same exception was thrown.
     
    does anyone know how to resolve it?  

    Thursday, April 22, 2010 9:05 AM

All replies

  • Instead of machine name(HV-BENDA), try giving the IP address of server...It might work.
    Friday, April 23, 2010 5:26 AM
  • nop.

     

    I have changed to

     

    string remoteMachine = "157.58.234.1";
    
    
    and got the same exception

    "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

     

    I'll try albeit it works as us when i put no credentials

    Friday, April 23, 2010 6:21 AM