WMI Query returns empty resultset

S

stigwulff

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
 
G

Guest

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
 
S

stigwulff

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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top