Postup:
Do projektu p°idejte
referenci na Microsoft WMI Scripting V1.1 Library. Na formulß° p°idejte 2
jmenovky (lblTitle, lblCPUlist), ListBox (lstCPU) a TextBox (txtCPU), kterΘmu
nastavte MultiLine na True. V deklaraΦnφ Φßsti formulß°e zapiÜte:
Private asCpuPaths() As String
Private m_objCPUSet As SWbemObjectSet
Private m_objWMINameSpace As SWbemServices
Pak na udßlost FormLoad:
Private Sub Form_Load()
Dim oCpu As SWbemObject 'WMI
objekt, v tomto p°φpad∞ lokßlnφ CPU
Dim sPath As String, sCaption As String
Dim lElement As Long
ReDim asCpuPaths(0) As String
On Error GoTo ErrorHandler
Set m_objWMINameSpace = GetObject("winmgmts:")
lstCPU.Clear
Set m_objCPUSet = m_objWMINameSpace.InstancesOf("Win32_Processor")
sCaption = m_objCPUSet.Count & " procesor"
If m_objCPUSet.Count <> 1 Then sCaption = sCaption &
"y"
sCaption = sCaption & " detekovßno na tomto
stroji."
lblTitle.Caption = sCaption
For Each oCpu In m_objCPUSet
With oCpu
sPath = .Path_ & ""
If sPath <> "" Then
lstCPU.AddItem
.Name
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 "Informace se nepoda°ilo zjistit. Nastala
chyba: " & _
Err.Description, , "WMI Demo"
GoTo CleanUp
End Sub
Na udßlost Click seznamu
procesor∙ zapiÜte:
Private Sub lstCPU_Click()
Dim oCpu As SWbemObject
Dim sInfoString As String
On Error Resume Next
Set oCpu = m_objCPUSet(asCpuPaths(lstCPU.ListIndex))
With oCpu
sInfoString = "Popis: " & .Description & vbCrLf
sInfoString = sInfoString & "ID
procesoru: " & .ProcessorID & vbCrLf
sInfoString = sInfoString &
"Stav " & .Status & vbCrLf
sInfoString = sInfoString & "V²robce: " & .Manufacturer & vbCrLf
sInfoString = sInfoString &
"Vyu₧itφ: " & .LoadPercentage & vbCrLf
sInfoString = sInfoString &
"Rychlost: " & .CurrentClockSpeed & " MHz" _
& vbCrLf
sInfoString = sInfoString &
"Maximßlnφ rychlost: " & .MaxClockSpeed _
& vbCrLf
sInfoString = sInfoString &
"Velikost Level 2 Cache: " & .L2CacheSize _
& vbCrLf
sInfoString = sInfoString &
"Rychlost Level 2 Cache: " & .L2CacheSpeed _
& vbCrLf
sInfoString = sInfoString &
"Podpora °φzenφ spot°eby: " _
& .PowerManagementSupported
End With
txtCpu.Text = sInfoString
End Sub
|