 |
| View previous topic :: View next topic |
| Author |
Message |
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Oct 10th, 2003 07:45 AM Post subject: Get Processor Info |
|
|
| Code: | '***********************************************************
'NOTES:
'YOU MUST HAVE WMI SDK INSTALLED. YOU CAN GET IT AT
'http://msdn.microsoft.com/downloads/sdks/wmi/default.asp
'Remember to add it in Project References!
'***********************************************************************
Private asCpuPaths() As String
Private m_objCPUSet As SWbemObjectSet
Private m_objWMINameSpace As SWbemServices
Option Explicit
Private Sub cmdDone_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim oCpu As SWbemObject 'WMI Object, in this case, local CPUs
Dim sPath As String, sCaption As String
Dim lElement As Long
ReDim asCpuPaths(0) As String
On Error GoTo ErrorHandler
'Get Default NameSpace, which will be the one for the local machine
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
Set m_objWMINameSpace = GetObject("winmgmts:")
lstCPU.Clear
'Get CPU set
Set m_objCPUSet = m_objWMINameSpace.InstancesOf("Win32_Processor")
sCaption = m_objCPUSet.Count & " processor"
If m_objCPUSet.Count <> 1 Then sCaption = sCaption & "s"
sCaption = sCaption & " detected on this machine"
lblTitle.Caption = sCaption
'Populate list box with CPU names
For Each oCpu In m_objCPUSet
With oCpu
sPath = .Path_ & ""
If sPath <> "" Then
lstCPU.AddItem .Name
'save path to array, so on machines with multiple CPUs,
'each can be identified and their info loaded into text box
lElement = IIf(asCpuPaths(0) = "", 0, UBound(asCpuPaths) + 1)
ReDim Preserve asCpuPaths(lElement) As String
asCpuPaths(lElement) = sPath
End If
End With
Next
If lstCPU.ListCount <> 0 Then lstCPU.ListIndex = 0
CleanUp:
Set oCpu = Nothing
Exit Sub
ErrorHandler:
MsgBox "CPU Information could not be displayed due to the following error: " & Err.Description, , "WMI Demo Failed"
GoTo CleanUp
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set m_objCPUSet = Nothing
Set m_objWMINameSpace = Nothing
End Sub
Private Sub lstCPU_Click()
Dim oCpu As SWbemObject
'Refer to SDK documentation for more detail about each of these properties
Dim sInfoString As String
On Error Resume Next
Set oCpu = m_objCPUSet(asCpuPaths(lstCPU.ListIndex))
With oCpu
sInfoString = "Description: " & .Description & vbCrLf
sInfoString = sInfoString & "Processor ID: " & .ProcessorID & vbCrLf
sInfoString = sInfoString & "Status: " & .Status & vbCrLf
sInfoString = sInfoString & "Manufacturer: " & .Manufacturer & vbCrLf
sInfoString = sInfoString & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
sInfoString = sInfoString & "Load Percentage: " & .LoadPercentage & vbCrLf
sInfoString = sInfoString & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
sInfoString = sInfoString & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
sInfoString = sInfoString & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
sInfoString = sInfoString & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
sInfoString = sInfoString & "Power Management Supported: " & .PowerManagementSupported
End With
txtCpu.Text = sInfoString
End Sub
'Conversions from code to string were developed
'based on information in WMI SDK documentation
Private Function AvailabilityToString(Code As Integer) As String
Dim sAns As String
Select Case Code
Case 1, 2
sAns = "Unknown"
Case 3
sAns = "Running/Full Power"
Case 4
sAns = "Warning"
Case 5
sAns = "In Test"
Case 6
sAns = "Not Applicable"
Case 7
sAns = "Power Off"
Case 8
sAns = "Off Line"
Case 9
sAns = "Off Duty"
Case 10
sAns = "Degraded"
Case 11
sAns = "Not Installed"
Case 12
sAns = "Install Error"
Case 13
sAns = "Power Save - Unknown"
Case 14
sAns = "Power Save - Low Power Mode"
Case 15
sAns = "Power Save - Standby"
Case 16
sAns = "Power Cycle"
Case 17
sAns = "Power Save - Warning"
Case Else
sAns = "Unknown"
End Select
AvailabilityToString = sAns
End Function |
_________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Oct 10th, 2003 07:46 AM Post subject: |
|
|
| Code: | Private Sub Command1_Click()
'========================
Dim WMI
Dim wmiWin32Objects
Dim wmiWin32Object
Dim ComputerName As String
ComputerName = "name" 'make sure this is YOUR computers name!!!!
Set WMI = GetObject("WinMgmts://" & ComputerName)
Set wmiWin32Objects = WMI.InstancesOf("Win32_Processor")
With wmiWin32Object
For Each wmiWin32Object In wmiWin32Objects
Text1(0).Text = .cpustatus
Text1(1).Text = .currentclockspeed
Text1(2).Text = .datawidth
Text1(3).Text = .Description
Text1(4).Text = .extclock
Text1(5).Text = .l2cachesize
Text1(6).Text = .l2cachespeed
Text1(7).Text = .Manufacturer
Text1(8[b][/b]).Text = .maxclockspeed
Text1(9).Text = .Name
Text1(10).Text = .processortype
Text1(11).Text = .Revision
Text1(12).Text = .role
Text1(13).Text = .socketdesignation
Text1(14).Text = .Status
Next
End With
End Sub |
_________________ No one is completely useless. They can at least be an example of what to avoid.
Last edited by P.T.A.M. on Dec 29th, 2003 07:32 PM; edited 1 time in total |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|