all groups > dotnet clr > october 2004 >
You're in the

dotnet clr

group:

WMI: Using ManagementClass.GetInstances()


WMI: Using ManagementClass.GetInstances() SlimFlem
10/26/2004 6:19:02 PM
dotnet clr:
Hi.

I am trying to instrument an object that gets loaded into ASP.NET Cache
during Windows_OnAuthenticate() in global.asax. I have properly put in place
all of the required instrumentation code for both the instrumented class and
done the proper install with installutil.exe. I used CIM Viewer to verify my
schema was published.

My object appears to be published without a problem...meaning no Exception
is thrown when calling Instrumentation.Publish(). When writing a command
line tool to connect to my published objects using:

ManagementClass wmi = new
ManagementClass(@"\\.\root\InventoryMgmt:ArtComPrincipal")

and then calling wmi.GetInstances() in a for loop, I get an exception of
type InvalidOperationException thrown. I really don't understand why this
is. Is there something different about doing this sort of thing when placing
instrumented objects in ASP.NET Cache?

This code is exactly the same from a console app I wrote this evening and it
works fine:

WMIObject obj = new WMIObject();
WMIObject.PublishToWMI(obj);

ManagementClass wmi = new ManagementClass(@"\\.\root\SlimFlem:WMIObject");

foreach (ManagementObject mobj in wmi.GetInstances())
{
Console.WriteLine(mobj.Properties["Prop1"].Value.ToString());
mobj.Dispose();
}

wmi.Dispose();

This of course is all running from a command line app, that's the only
difference.

Any ideas why I get the InvalidOperationException would be grealty
appreciated.
RE: WMI: Using ManagementClass.GetInstances() SlimFlem
10/29/2004 4:25:02 PM
I am local admin on my box at work. What I ended up doing was to move the
Instrumentation.Publish() call inside the assembly that actually creates and
loads my WindowsPrincipal object. This makes better sense anyway because
this doesn't really belong in global.asax. This works great.

In global.asax, I now simply fire a WMI event to indicate a user was
authenticated on to the site. I subscribe to this event in my WMI consumer
and then grab the instance of the Instance class and dump the details. This
is working just like I wanted.

thanks for the reply.


[quoted text, click to view]
RE: WMI: Using ManagementClass.GetInstances() samspONLINE NO[at]SPAM microsoft.com (
10/29/2004 11:00:15 PM
Not being an expert in Instrumentation, I would suspect this is a permissions/rights thing.

Asp.net runs under a really low privelige account. I would suspect that WMI needs admin rights to be able to manage objects. You are probably admin on your own
machine, which is why it works for you in a console app.

Sam
The web platform & tools team
--------------------
[quoted text, click to view]

AddThis Social Bookmark Button