473,473 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Mar 21 '07 #1
2 4414
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

Mar 21 '07 #2
On 21 Mar., 12:32, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
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"
Mar 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ralph Freshour | last post by:
I'm not sure the follow multiple table query is the right way to do what I need to do although it seems to be working: $php_SQL = "SELECT * ". "FROM basics, personal, photos ". "WHERE...
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
21
by: CSN | last post by:
I have a pretty simple select query that joins a table (p) with 125K rows with another table (pc) with almost one million rows: select p.* from product_categories pc inner join products p on...
0
by: lesperancer | last post by:
I've got a sql server view that returns data, as a linked table to access97 (qryPlannedPurPT) this link table is used in an access query (qryPlannedPUR) that uses all of the linked table fields...
7
by: zwasdl | last post by:
When I swtich to design view from data view, the query results are lost, and I have to run again to get it. Is there an option in access to keep the data when I switching views? I know I can copy...
12
by: robertino | last post by:
Hi all, I've put together a few SPs to produce a BOM (bill of materials) listing, which together use a couple of global temp tables, and return the results from a cursor. Here's the code: ...
3
by: 0to60 | last post by:
Please help! I'm using the following code to get an XML doc: string str = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=12345&city=addison"; System.Net.HttpWebRequest request =...
3
by: msrviking | last post by:
Hello everybody, After several attempts of writing the query, I had to post my requirement in the forum. Here is what I have, what I need and what I did. Table A Col1 Col2 1 Nm1
6
by: joerg | last post by:
Hello world, my program connects to a db2 database and needs to find out the column names and data types for a specific table. The code works fine with mysql and derby, but returns an empty...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.