Processor information

Beginners tend to ask how they can write a program that displays the processor model of a computer. There are a few different methods that can be used for this. You can call the SET command or you can query the registry. To call the SET command, connect to the output from a process and find the processor information in the output data.

'Load processor information.
Dim ProcessorIdentifier = ""
Dim Ps = New ProcessStartInfo("cmd", "/c set")
Dim Raw As String
Ps.RedirectStandardOutput = True
Ps.UseShellExecute = False
Using P = Process.Start(Ps)
   P.WaitForExit()
   Raw = P.StandardOutput.ReadToEnd()
End Using
Dim Rows() = Raw.Split(ControlChars.CrLf.ToCharArray(),
             StringSplitOptions.RemoveEmptyEntries)
For Each Row As String In Rows
   If Row.StartsWith("PROCESSOR_IDENTIFIER=") Then
      ProcessorIdentifier = Row.Substring(21)
      Exit For
   End If
Next

'Display processor information.
MessageBox.Show(ProcessorIdentifier)

Another method is to check the computer registry in HKEY_LOCAL_MACHINE at HARDWARE\DESCRIPTION\System\CentralProcessor\0. The key is Identifier.

'Load processor information.
Dim ProcessorIdentifier = ""
Dim Hardware = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE")
If Not Hardware Is Nothing Then
   Dim CP = Hardware.OpenSubKey("DESCRIPTION\System\CentralProcessor\0")
   ProcessorIdentifier = If(Not CP Is Nothing,
                CP.GetValue("Identifier").ToString(), "")
End If

'Display processor information.
MessageBox.Show(ProcessorIdentifier)

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll:

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Comments

Important information: If you have not commented before, your comment will be reviewed before it is published. This means that you will not see it immediately, but I have received it. This is not because I want to filter comments, but because I want to prevent spam and advertising.

Leave a Reply

Your email address will not be published. Required fields are marked *