Jump to content

CPU name in label


Recommended Posts

Hi

 

I´m quiet new to autoit and i have found this script, but I can´t get it to show the processor (or the $read) in a gui label instead of opening a messagebox.

Does anybody know how?

$PID = Run("wmic cpu get name", '', '', 0x2)
While 1
  $read = StdoutRead($PID)
  If @error Then ExitLoop
  MsgBox(0, '', $read)
WEnd
Edited by Melba23
Added tags
Link to comment
Share on other sites

  • Moderators

Misuna,

Welcome to the AutoIt forum. :)

But please pay attention to where you post - the "Developer Chat" section where you started this thread is not for general support questions. I have moved the thread for you, but would ask you to be more careful in future. ;)

M23

P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Welcome to Autoit and the forum!

You need to create a GUI first. See GUICreate in the help file for an example.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I already have a GUI, the problem is that i don´t know how to get the "answer" (the name of the CPU) written on a label.

This is the GUI/programm

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=prog.ico
#AutoIt3Wrapper_Outfile=Pc Komponenter .exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Region find OS
Dim $OS = @OSVersion ; OS Version
Dim $text = ""; Output text for message box.
Switch $OS ; A Switch statement. We are going to make the value returned by @OSVERSION more readable.
Case "WIN_2008"
$OS = "Windows Server 2008"
Case "WIN_8"
$OS = "Windows 8"
Case "WIN_7"
$OS = "Windows 7"
Case "WIN_VISTA"
$OS = "Windows Vista"
Case "WIN_2003"
$OS = "Windows Server 2003"
Case "WIN_XP"
$OS = "Windows XP"
Case "WIN_2000"
$OS = "Windows 2000"
Case "WIN_NT4"
$OS = "Windows NT 4.0"
Case "WIN_ME"
$OS = "Windows ME"
Case "WIN_98"
$OS = "Windows 98"
Case "WIN_95"
$OS = "Windows 95"
Case Else
$OS = "Ukendt"
EndSwitch
$text &= "OS = " & $OS
#EndRegion

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include "CompInfo.au3"
#include-once
#Region ### START Koda GUI section ### Form=e:\autoit\pc system\pc komponenter.kxf
;GUItal f. eks. ("Components Finder", 615, 438, 192, 124) = ("tekst", længde fra venstre kant, længde fra top kant, block længde (fra side til side), sidste vides ikke...
Opt("GuiOnEventMode", 1)
$Form1_1 = GUICreate("Hvad sidder der i min computer?", 614, 436, 193, 125)
$Components = GUICtrlCreateLabel("Komponenter", 208, 32, 190, 43)
GUICtrlSetFont(-1, 24, 400, 0, "Calibri")
$ComputerName = GUICtrlCreateLabel("Computernavn", 472, 8, 130, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Name = GUICtrlCreateLabel(@ComputerName, 472, 32, 100, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
$Bruger = GUICtrlCreateLabel(@UserName, 472, 48, 100, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
$OS = GUICtrlCreateLabel($text, 472, 62, 128, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
$CPU = GUICtrlCreateLabel("Processor", 48, 120, 80, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Hvilken_CPU = GUICtrlCreateLabel("Which CPU", 208, 120, 106, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$GPU = GUICtrlCreateLabel("Grafikkort", 48, 176, 80, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Corbel")
$Hvilken_GPU = GUICtrlCreateLabel("Hvilken_GPU", 208, 176, 108, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$RAM = GUICtrlCreateLabel("Hukommelse (KB)", 48, 232, 140, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
Local $aMem = MemGetStats()
$Hvor_Meget_RAM = GUICtrlCreateLabel($aMem[1], 208, 232, 150, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Hvor_Meget_RAM = GUICtrlCreateLabel("speed", 308, 232, 150, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Hvor_Meget_RAM = GUICtrlCreateLabel("Mhz", 350, 232, 150, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$HDD_Space = GUICtrlCreateLabel("Harddisk (MB)", 48, 344, 140, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Corbel")
Local $iFreeSpace = DriveSpaceFree(@HomeDrive & "\")
$Hvor_Meget_Lagerplads = GUICtrlCreateLabel($iFreeSpace, 208, 344, 150, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$af = GUICtrlCreateLabel("/", 400, 344, 45, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
Local $iTotalSpace = DriveSpaceTotal(@HomeDrive & "\")
$Hvor_Meget_Totallagerplads = GUICtrlCreateLabel($iTotalSpace, 410, 344, 200, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Mobo = GUICtrlCreateLabel("Bundkort", 48, 288, 80, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Hvilket_Bundkort = GUICtrlCreateLabel("Mobo", 208, 288, 141, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Calibri")
$Copyright_MisunaDK = GUICtrlCreateLabel("Copyright MisunaDK", 504, 416, 102, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Calibri")
$Button1 = GUICtrlCreateButton("Luk", 312, 400, 73, 25)
GUICtrlSetOnEvent($Button1, "Close")
$Button2 = GUICtrlCreateButton("Bedøm", 232, 400, 75, 25)
GUICtrlSetOnEvent($Button2,"Rate")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
        Case $Button2
    EndSwitch
WEnd

 Func Close()
    Exit
EndFunc

 Func Rate()
    ShellExecute("http://www.youtube.com/misunadk")
EndFunc

Func _End()
    Exit
EndFunc
Link to comment
Share on other sites

Are you trying to get the brand name/model of the CPU. What do you mean by name?

 

Edit: Running on that assumption, I did a little digging and found the CPU info in the registry, you can also do a regread to pull that info out. You'll have to do something to confirm the file path for Win7, Win8, and WinXP but there might be a cleaner way to do it. I'm at work so I can only put so much time towards this.

Edited by JayHawkfl

Thanks for your time

 

Link to comment
Share on other sites

$Output = ""
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_Processor", "WQL", 0x10 + 0x20)
If IsObj($colItems) then
   For $objItem In $colItems
       $Output &= $objItem.Name
   Next
Endif
Msgbox(0,"WMI Output", $Output )

; GuiCtrlSetData($label, $Output )  ; to write it in a label

Link to comment
Share on other sites

this func will put the cpu name in the $read variable and return it to caller

MsgBox(0, "cpu name", CPU_name())

$My_CPU_name =  CPU_name() ; example to assign name to a variable

Func CPU_name()
    Local $PID = Run("wmic cpu get name /value", '', '', 0x2), $read = ""
    Do
        $read &= StdoutRead($PID)
    Until @error
    Return StringStripWS($read,3)
EndFunc   ;==>CPU_name

edit:

added /value parameter in run() statement to get back only the raw value

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hello,

much faster, than:

MsgBox(0, "cpu name", CPU_name())

$My_CPU_name =  CPU_name() ; example to assign name to a variable

Func CPU_name()
    Local $PID = Run("wmic cpu get name /value", '', '', 0x2), $read = ""
    Do
        $read &= StdoutRead($PID)
    Until @error
    Return StringStripWS($read,3)
EndFunc   ;==>CPU_name

try:

$My_CPU_name=RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString" )
MsgBox(0,"CPU Name (String)", $My_CPU_name)

Greetings.

edit.

like @JayHawkfl, on 19 Mar 2014 - 1:37 PM, said:


Are you trying to get the brand name/model of the CPU. What do you mean by name?

 

Edit: Running on that assumption, I did a little digging and found the CPU info in the registry, you can also do a regread to pull that info out. You'll have to do something to confirm the file path for Win7, Win8, and WinXP but there might be a cleaner way to do it. I'm at work so I can only put so much time towards this.

 

Edited by Wilenty
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...