ERROR when trying do display CPU info because of Option Strict On

  • Thread starter Thread starter Chrisy781
  • Start date Start date
C

Chrisy781

Guest
Hey guys I want do display cpu info but it shows 6 error when I debug my program>

a7f971ad6d13b013a5abdb0ef48c6224._.png


I have Option Strict On

This is my code , Please help...

Option Strict On
Imports IWshRuntimeLibrary
Imports System
Imports System.Management
Imports Microsoft.Win32
Imports System.Diagnostics.FileVersionInfo
Imports System.Runtime.InteropServices



Public Class Form1


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Label10.Text = (CDbl(getWMIInfo("MaxClockSpeed") / 1000) & " Ghz")
Label16.Text = System.Environment.ProcessorCount.ToString

Dim voltage As String = getWMIInfo("CurrentVoltage")

If the chars returned is two then add a decimal between the 2x numbers.
If Not voltage.Length = 0 AndAlso voltage.Length = 2 Then

Add a decimal point.
Dim value As String = voltage.Substring(0, 1) & "." & _
voltage.Substring(1, 1)

Label17.Text = (value & " v")

voltage = Nothing
value = Nothing

Else

Label17.Text = ("n/a")

End If

The registry path to get the info we are wanting.
Dim str As String = "HARDWARE\DESCRIPTION\System\CentralProcessor"

Returns how many SubKeys are under “CentralProcessor”.
The subKey count under this key =’s the‘total cpu’s your system has installed.
Of course, 90% or so will only have 1x subkey denoting a‘single cpu system.
My system happens to return 2x subkeys since I have a Dual Core system.
Dim cpuCount As Integer = My.Computer.Registry.LocalMachine.OpenSubKey(str, False).SubKeyCount



Dim cpuMhz As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
"HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("~mhz")
Label18.Text = cpuMhz
Dim cpuName As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
"HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("ProcessorNameString")
Label19.Text = cpuName
Dim cpuVendorID As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
"HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("VendorIdentifier")
Label20.Text = cpuVendorID
Dim cpuIdentifier As String = My.Computer.Registry.LocalMachine.OpenSubKey( _
"HARDWARE\DESCRIPTION\System\CentralProcessor\0").GetValue("Identifier")
Label21.Text = cpuIdentifier

Catch ex As Exception
End Try
End Sub

Public Function getWMIInfo(ByVal wmiObjectInfo As String, Optional ByVal _
wmiRelativePath As String = "Win32_Processor") As String


[wmiClass.Path.RelativePath] = "Win32_Processor"

CPUName = "Name"
CPUSocket = "SocketDesignation"
CPUClockspeed = "CurrentClockSpeed"
CPUMaxClockspeed = "MaxClockSpeed"
MoboBusSpeed = "ExtClock"
Manufacturer = "Manufacturer"
CPUFamily = "Family"
CPU-L2 Cache Size = "L2CacheSize"
CPULoadPercent = "LoadPercentage"
CPUArchitecture = "Architecture" - 0 = x86 or 32 Bit, 1 = Mips, 2 = Alpha, 3 = PowerPC, 6 = Intel Itanium, 9 = x64
CPUStatus = "CpuStatus" - 0 = unKnown, 1 = Enabled, 2 = Disabled in Bios by User, 3 = Disabled by Bios (Post Error), 4 = Idle, 7 = Other
CPUDataWidth = "DataWidth"
CPUDescription = "Description"
CPUDeviceID = "DeviceID"
CPULevel = "Level"
CPUType = "ProcessorType" - 1 = Other, 2 = UnKnown, 3 = Central, 4 = Math Co-Processor, 5 = DSP CPU, 6 = Video CPU
CPURevision = "Revision"
CPUStepping = "Stepping"
CPUSocketUpgrade = "UpgradeMethod" - Values are: 1 - 18
CPUVersion = "Version" - Model? and Stepping? is returned.
CPUVoltage = "CurrentVoltage"

Get

On Error Resume Next
getWMIInfo = Nothing

Try

Dim wmiClass As New System.Management.ManagementClass
Dim wmiObject As New System.Management.ManagementObject

wmiClass.Path.RelativePath = wmiRelativePath

counts = wmiClass.GetInstances.Count

For Each wmiObject In wmiClass.GetInstances

MsgBox(wmiObject(wmiObjectInfo))

This will add up each value.
getWMIInfo += Val((wmiObject(wmiObjectInfo)))


Return getWMIInfoTest

Next

Return getWMIInfo


This is just used to get how many cpus are really installed.
counts = wmiClass.GetInstances.Count

Return "Hmmm"

Catch exc As Exception

MsgBox(exc.ToString)


Return "n/a"

wmiObject(wmiObjectInfo) .Trim)
Resume Next

End Try
Return Nothing
End Get

End Function



End Class




Thanks in Advanced.

Continue reading...
 
Back
Top