WMI Query returns empty resultset

Discussion in 'ASP .Net' started by stigwulff@gmail.com, Mar 21, 2007.

  1. Guest

    I have made a ASP.NET ver. 2 webservice that runs on an Exchange 2003
    server.
    In that webservice I want to get the size of the mailboxes on the
    Exchange server.
    I try to use WMI and the System.Managment in C#.
    But when I call the Get() method on the ManagementObjectSearcher
    object it returns an empty resultset (collection).
    If I take the same code and put it into a C# windows application
    instead of the webservice and run the application on the Exchange
    server it returns a collection with all the information I want.

    Here is the code I use:

    ConnectionOptions objconn = new System.Management.ConnectionOptions();
    objconn.Impersonation =
    System.Management.ImpersonationLevel.Impersonate;
    objconn.EnablePrivileges = true;
    string cServername = "EXCHANGE01";
    ManagementScope exmangescope = new ManagementScope(@"\\EXCHANGE01
    \root\MicrosoftExchangeV2", objconn);
    ObjectQuery objquery = new ObjectQuery("SELECT * FROM
    Exchange_Mailbox");
    ManagementObjectSearcher objsearch = new
    ManagementObjectSearcher(exmangescope, objquery);
    ManagementObjectCollection queryCollection1 = objsearch.Get(); //
    This returns zero resultset
    string strDisplay;
    foreach (ManagementObject instmailbox in queryCollection1)
    {
    strDisplay = instmailbox["MailboxDisplayName"].ToString() + " "
    + instmailbox["size"].ToString();
    }

    I have a try catch around all the code and there are no exceptions.

    What can be wrong?

    Stig
    , Mar 21, 2007
    #1
    1. Advertising

  2. On Mar 21, 11:25 am, wrote:

    > If I take the same code and put it into a C# windows application
    > instead of the webservice and run the application on the Exchange
    > server it returns a collection with all the information I want.


    The Win app runs on your account, ASP.NET used an ASPNET account which
    I suppose has no rights to browse your Exchange (I'm not sure why it
    didn't return the "Access Denied" message...). Instead of using
    impersonation, try to connect with predefined user:

    objconn.Username = "userid";
    objconn.Password = "password";

    And see if it solved the problem, or not
    Alexey Smirnov, Mar 21, 2007
    #2
    1. Advertising

  3. Guest

    On 21 Mar., 12:32, "Alexey Smirnov" <> wrote:
    > On Mar 21, 11:25 am, wrote:
    >
    > > If I take the same code and put it into a C# windows application
    > > instead of the webservice and run the application on the Exchange
    > > server it returns a collection with all the information I want.

    >
    > The Win app runs on your account, ASP.NET used an ASPNET account which
    > I suppose has no rights to browse your Exchange (I'm not sure why it
    > didn't return the "Access Denied" message...). Instead of using
    > impersonation, try to connect with predefined user:
    >
    > objconn.Username = "userid";
    > objconn.Password = "password";
    >
    > And see if it solved the problem, or not


    I have tried to specify a username and password but it comes up with
    this exception:

    "User credentials cannot be used for local connections"
    , Mar 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Semmelmann

    WMI-Query of a Remote Machine

    Andreas Semmelmann, Oct 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,812
    Andreas Semmelmann
    Oct 16, 2003
  2. Winterminute
    Replies:
    0
    Views:
    3,090
    Winterminute
    Dec 4, 2003
  3. vizlab
    Replies:
    3
    Views:
    4,176
    Michael Bar-Sinai
    Oct 17, 2007
  4. david.karr
    Replies:
    17
    Views:
    1,132
    Arne Vajhøj
    Aug 23, 2009
  5. Arjen
    Replies:
    1
    Views:
    127
    Lasse Reichstein Nielsen
    Jun 26, 2004
Loading...

Share This Page