ProcessorId String Correcty?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bjorn94
Posts: 4
Joined: 05 Mar 2022 06:35

ProcessorId String Correcty?

#1 Post by Bjorn94 » 05 Mar 2022 06:39

Hi everyone, I have a problem, with this code it should tell me that it is correct, instead it says that it is not, you have to put your processorID inside the quotes, I did not put mine because it would not make sense, someone can tell me why it does not work correctly ?

Code: Select all

@echo off
Set cpuid= wmic cpu get processorid^|more +1
%cpuid%
if NOT "%cpuid%"=="  " (goto A) else (goto B)
:B
echo It worked
pause > nul
:A
echo It does not work
pause > nul
Last edited by aGerman on 05 Mar 2022 09:24, edited 1 time in total.
Reason: Use code formatting!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ProcessorId String Correcty?

#2 Post by aGerman » 05 Mar 2022 09:23

There is no syntax in batch to just use SET for the assignment of the output of a command. The command has to be executed in a FOR /F loop in order to capture its output. Furthermore, WMIC outputs weird line endings. I'm used to working around it in a second FOR /F.

Code: Select all

@echo off &setlocal
set "cpuid="
for /f "delims=" %%i in ('wmic cpu get ProcessorId /value') do for /f "tokens=2 delims==" %%j in ("%%i") do set "cpuid=%%j"
if not defined cpuid (
  echo Unable to get the processor ID
  pause
  exit /b
)

echo %cpuid%
pause
Steffen

Bjorn94
Posts: 4
Joined: 05 Mar 2022 06:35

Re: ProcessorId String Correcty?

#3 Post by Bjorn94 » 05 Mar 2022 10:05

Wow, thanks, N.1 :D :D :D

Post Reply