Link to home
Start Free TrialLog in
Avatar of jindalee
jindalee

asked on

ManagementObjectCollection usage

I am trying to use the ManagementObjectCollection class to get some system information. However, the attcahed code snippet gives me the errors:
   "ManagementClass not defined"
   "ManagementObjectCollection not defined"
   "ManagementObjectCollection.ManagementObjectEnumerator" not defined.

From what I can see in MSDN, I have to import System and System.Management to get these classes.

I have both imports in my code but still get the errors.

I am using Visual Studio.Net (Visual Basic 2008) on a WinXP SP3, .Net 3,.5 PC.

Can someone please advise what I am missing.

Thanks


Dim ManClass As ManagementClass = New ManagementClass("Win32_ComputerSystem")
Dim ManObj As ManagementObjectCollection = ManClass.GetInstances()
Dim ManOblCollection As ManagementObjectCollection.ManagementObjectEnumerator = ManObj .GetEnumerator
ManOblCollection .MoveNext()
s = ManOblCollection .Current.Properties("CurrentTimeZone").Value.ToString()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jindalee
jindalee

ASKER

I'm still learning. I have the following at the top of my code:

IMports System
IMports System.Management

Is that differenmt from adding a reference?
Thank you. I found that I had to add theimports as references even though I had them at the top of the source file. Works a treat.
I didn't get a chance to respond.  Did you answer your own question about adding a reference?