Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Processor information

2013-05-28

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)

Categories: VB.NET

Leave a Reply

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



En kopp kaffe!

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

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips