🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using more than one WMI class in VB?

Started by
2 comments, last by Creeo 19 years, 11 months ago
Hi all, I am using WMI to get details about computer hardware and was just wondering how you would use more than one of the classes. I am new to VB and it seems simple enough. Just having problems (something probably very stupid!). Here is some of the code anyway: ----------------------------------------------------------------- On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard",,48) For Each objItem in colItems Wscript.Echo "Caption: " & objItem.Caption Wscript.Echo "Description: " & objItem.Description Wscript.Echo "Manufacturer: " & objItem.Manufacturer Wscript.Echo "Model: " & objItem.Model Wscript.Echo "Name: " & objItem.Name Wscript.Echo "Product: " & objItem.Product Wscript.Echo "SlotLayout: " & objItem.SlotLayout Wscript.Echo "Tag: " & objItem.Tag Wscript.Echo "Version: " & objItem.Version Next On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48) For Each objItem in colItems Wscript.Echo "BuildNumber: " & objItem.BuildNumber Wscript.Echo "Caption: " & objItem.Caption Wscript.Echo "Description: " & objItem.Description Wscript.Echo "Manufacturer: " & objItem.Manufacturer Wscript.Echo "Name: " & objItem.Name Wscript.Echo "ReleaseDate: " & objItem.ReleaseDate Wscript.Echo "SMBIOSBIOSVersion: " & objItem.SMBIOSBIOSVersion Wscript.Echo "SMBIOSMajorVersion: " & objItem.SMBIOSMajorVersion Wscript.Echo "SMBIOSMinorVersion: " & objItem.SMBIOSMinorVersion Wscript.Echo "SoftwareElementID: " & objItem.SoftwareElementID Wscript.Echo "TargetOperatingSystem: " & objItem.TargetOperatingSystem Wscript.Echo "Version: " & objItem.Version Next On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive",,48) For Each objItem in colItems Wscript.Echo "Caption: " & objItem.Caption Wscript.Echo "Description: " & objItem.Description Wscript.Echo "DeviceID: " & objItem.DeviceID Wscript.Echo "Drive: " & objItem.Drive Wscript.Echo "Id: " & objItem.Id Wscript.Echo "Manufacturer: " & objItem.Manufacturer Wscript.Echo "MediaType: " & objItem.MediaType Wscript.Echo "Name: " & objItem.Name Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID Wscript.Echo "RevisionLevel: " & objItem.RevisionLevel Wscript.Echo "TransferRate: " & objItem.TransferRate Wscript.Echo "VolumeName: " & objItem.VolumeName Wscript.Echo "VolumeSerialNumber: " & objItem.VolumeSerialNumber Next ----------------------------------------------------------------- If anyone can point out my stupid mistakes then I would be greatful! Thanks David
Advertisement
Could you explain a bit more what your trying to do?

- Creeo
Hi Creeo,

I am just trying to display the hardware info using the WMI classes but am not good with visual basic so I dont know how to use more than one class. I can get the information from one class fine e.g.

-----------------------------------------------------------------
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Model: " & objItem.Model
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Product: " & objItem.Product
Wscript.Echo "SlotLayout: " & objItem.SlotLayout
Wscript.Echo "Tag: " & objItem.Tag
Wscript.Echo "Version: " & objItem.Version
Next
-----------------------------------------------------------------

Will work fine for me but I want to be able to get info from lots of different classes as outlined above.

All I need to know is what is wrong with my loop as I think this is the problem. Or perhaps I need to remname a few things so there isnt duplication in the set... names etc?

Hope someone can help

Thanks

David
I'm sorry, i dont understand EXACTLY what you mean by classes.

And i'm sorry if i'm giving you the wrong information when i'm telling you this, because this is basic information for visualbasic.. But it seems you have no output for the information.

If instead of echoing it, put a label on the form, and where the echo is...

-----------------------------------------------------------------
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard",,48)
For Each objItem in colItems
lblcaption.caption = "Caption: " & objItem.Caption
lbldesc.caption = "Description: " & objItem.Description
lblmanu.caption = "Manufacturer: " & objItem.Manufacturer
lblmodel.caption = "Model: " & objItem.Model
ETC
Next
-----------------------------------------------------------------

I'm not sure if that's exactly what your looking for, and i'm sorry if it isnt.

Perhaps you could define what you mean by classes a bit more, i'm not a pro at visual basic myself, but i have a few years of experience(mostly basics) behind it.

- Creeo

This topic is closed to new replies.

Advertisement