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