Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
13Activity
0 of .
Results for:
No results containing your search query
P. 1
Getting Hardware Information Using Visual Basic

Getting Hardware Information Using Visual Basic

Ratings: (0)|Views: 2,422|Likes:

More info:

Published by: Zaeni Marjiyanto, A.md on Jan 18, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

11/26/2012

pdf

text

original

 
Getting Hardware Information Using VisualBasic.NET and VBScript
(Page 1 of 4 )This article explains how to retrieve hardware information using both Visual Basic.NET andVBScript. We shall cover motherboards, on board devices and processors.A downloadable file for this story is available here. The sample downloadable solution (zip) was entirely developed using Visual Studio.NET 2003Enterprise Architect on Windows Server 2003 Standard Edition. But, I am confident that itwould work with other versions of Windows (which support .NET 1.1) versions as well.I contributed several articles covering WMI with VB.NET and VBScript, including the articleson introductory or basic topics concerning WMI. I even contributed a series of about six articleson “WMI Programming on VB.NET” covering several aspects of WMI. I strongly suggestyou go through the series, before going through this article.
Listing the “On Board Devices” available
Some scenarios may require some properties of the onboard devices of the motherboard to belisted. Instead of opening the CPU and going through each and every device, we can retrieve thesame information dynamically using VB.NET. The following VB.NET code should supportretrieving some minimum information about devices available on your system.
Private
 
SubButton1_Click(ByValsenderAsSystem.Object,ByValeAs System.EventArgs)HandlesButton1.Click
 
Try
 
DimsearcherAs NewManagementObjectSearcher( _
 
"root\CIMV2", _
 
"SELECT * FROM Win32_OnBoardDevice")
 
DimdtAsDataTable = globals.getOnBoardDeviceStructure
 
For EachqueryObjAsManagementObjectInsearcher.Get()
 
globals.addOnBoardDevice(dt, queryObj("Description"),Convert.ToString(queryObj("DeviceType")), queryObj("Enabled"),queryObj("Tag"))
 
Next
 
Me.DataGrid1.DataSource = dt
 
CatcherrAsManagementException
 
MessageBox.Show("An error occurred while querying for WMI data:" & err.Message)
 
End Try
 
End Sub
You can achieve the same thing with VBScript as follows:
strComputer
 
= "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
 
Set colItems = objWMIService.ExecQuery( _
 
"SELECT * FROM Win32_OnBoardDevice",,48)For Each objItem in colItemsWscript.Echo "Description: " & objItem.Description
 
Wscript.Echo "DeviceType: " & objItem.DeviceType
 
Wscript.Echo "Enabled: " & objItem.Enabled
 
Wscript.Echo "Tag: " & objItem.TagNext
Getting Hardware Information Using VisualBasic.NET and VBScript - The class Win32OnBoardDevice in detail
(Page 2 of 4 )In the previous section, I touched on only some of the most important properties from theexisting WMI class (Win32_OnBoardDevice); had I done otherwise, it would have made the program too long. The program above will list the description, device type and tag properties.You can further extend the program with several other properties available in the“Win32_OnBoardDevice” class. You can even refer to MSDN online for further properties. Now, let us go into the details of the properties I mentioned in the previous section.
Description
: This property gives you a better explanation of the object.
Device Type
: In general, there will be many types of devices “OnBoard.” The devices includeVideo, SCSI controller, Ethernet (especially for LAN), and so on. The “Device Type” propertyexplains the type of device being represented. The following is the table extracted from MSDNto provide you with an explanation of those values returned by “Device Type.”
ValueMeaning
1Othe2Unknown3Video4SCSIController 
 
5Ethernet6Token Ring7Sound 
Enabled
: This property specifies whether the device is enabled to work or not. Sometimes, italso depends on hardware settings or configuration.
Tag
: This property gives you the unique identifier of the onboard device available for your system.
Listing the processors available
In previous sections, we have seen only “On Board Devices.” Now, let us go through theinformation related to the processors existing in your system. The following VB.NET codeshould support retrieving some minimum information about processors available on your system.
Private
 
SubButton1_Click(ByValsenderAsSystem.Object,ByValeAs System.EventArgs)HandlesButton1.Click
 
Try
 
DimsearcherAs NewManagementObjectSearcher( _
 
"root\CIMV2", _
 
"SELECT * FROM Win32_Processor")
 
DimdtAsDataTable = globals.getProcessorStructure
 
For EachqueryObjAsManagementObjectInsearcher.Get()
 
globals.addProcessorDevice(dt,Convert.ToString(queryObj("Availability")), queryObj("Caption"),Convert.ToString(queryObj("CpuStatus")),Convert.ToString(queryObj("CurrentClockSpeed")), queryObj("DeviceID"),Convert.ToString(queryObj("Level")), queryObj("Name"),queryObj("ProcessorId"), Convert.ToString(queryObj("ProcessorType")),queryObj("SystemName"))
 
Next
 
Me.DataGrid1.DataSource = dt
 
CatcherrAsManagementException
 
MessageBox.Show("An error occurred while querying for WMI data:" & err.Message)
 
End Try
 
End Sub
You can achieve the same thing with VBScript as follows:
strComputer
 
= "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")Set colItems = objWMIService.ExecQuery( _
 
"SELECT * FROM Win32_Processor",,48)For Each objItem in colItemsWscript.Echo "Availability: " & objItem.Availability
 
Wscript.Echo "Caption: " & objItem.Caption

Activity (13)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Asad Hayat liked this
Maximo Ginez III liked this
bscmscmca liked this
Peltztier liked this
manjunath_bhat liked this
harryrp liked this
harryrp liked this
bknas liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->