locked
COMException while accessing OCS server remotly using C# RRS feed

  • Question

  • Dear Developers,

    I have written this code ( C# 2005 )to connect remotly to OCS 2007 server to get domain data.my account is domain admin

     

    using System;

    using System.Management;

    using System.Windows.Forms;

    using System.Runtime.InteropServices;

    namespace WMISample

    {

    public class MyWMIQuery

    {

    public static void Do(string serverIP)

    {

    try

    {

    ManagementObjectSearcher searcher =

    new ManagementObjectSearcher(@"\\" + serverIP + @"\root\CIMV2",

    "SELECT * FROM MSFT_SIPDomainData");

    foreach (ManagementObject queryObj in searcher.Get())

    {

    MessageBox.Show("Address: " + queryObj["Address"]);

    //MessageBox.Show("Authoritative: " + queryObj["Authoritative"]);

    //MessageBox.Show("DefaultDomain: " + queryObj["DefaultDomain"]);

    //MessageBox.Show("InstanceID: " + queryObj["InstanceID"]);

    }

    }

    catch (ManagementException e)

    {

    MessageBox.Show("ManagementException: \n" + e.Message + "\n" + e.ErrorCode.ToString());

    }

    catch (COMException e)

    {

    MessageBox.Show("COMException: \n" + e.Message + "\n" + e.ErrorCode.ToString());

    }

    catch (UnauthorizedAccessException e)

    {

    MessageBox.Show("UnauthorizedAccessException: \n" + e.Message);

    }

    catch (Exception e)

    {

    MessageBox.Show("Exception: \n" + e.Message + "\n" + e.GetType().FullName);

    }

    }

    }

    }

     

    but when i run the application and  pass SERVER IP  i get this error::

     

    COM Exception Error  with no message and error code is -2147016672

     

    Can any one help me to tell me what's the problem ?

     

    although when i try the same code but by replaceing

    ManagementObjectSearcher searcher =

    new ManagementObjectSearcher(@"\\" + serverIP + @"\root\CIMV2",

    "SELECT * FROM MSFT_SIPDomainData");

    with

    ManagementObjectSearcher searcher =

    new ManagementObjectSearcher( @"\root\CIMV2",

    "SELECT * FROM MSFT_SIPDomainData");

     

    the code run perfect without any error

     

    any one help me ??

    Sunday, November 25, 2007 3:01 PM