I am quite new to vb.net and want to get the processor id of the pc but i am not getting any easy solution to this.
I have found the following code on this site but unable to use to it.
I want to use the code in form load event.
the post was as below,but it is beyond my senses
'YOU MUST HAVE WMI SDK INSTALLED. YOU CAN GET IT AT
'http://msdn.microsoft.com/downloads/sdks/wmi/default.asp
'***********************
Private asCpuPaths() As String
Private mobjCPUSet As SWbemObjectSet
Private mobjWMINameSpace 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 mobjCPUSet = mobjWMINameSpace.InstancesOf("Win32Processor")
sCaption = mobjCPUSet.Count & " processor"
If mobjCPUSet.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 mobjCPUSet
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 FormUnload(Cancel As Integer)
Set mobjCPUSet = Nothing
Set m_objWMINameSpace = Nothing
End Sub
Private Sub lstCPUClick()
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 = mobjCPUSet(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
Enter your message below
Sign in or Join us (it's free).