Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   WMI Query returns empty resultset (http://www.velocityreviews.com/forums/t485924-wmi-query-returns-empty-resultset.html)

stigwulff@gmail.com 03-21-2007 10:25 AM

WMI Query returns empty resultset
 
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


Alexey Smirnov 03-21-2007 11:32 AM

Re: WMI Query returns empty resultset
 
On Mar 21, 11:25 am, stigwu...@gmail.com 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


stigwulff@gmail.com 03-22-2007 08:21 AM

Re: WMI Query returns empty resultset
 
On 21 Mar., 12:32, "Alexey Smirnov" <alexey.smir...@gmail.com> wrote:
> On Mar 21, 11:25 am, stigwu...@gmail.com 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"




All times are GMT. The time now is 04:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.