Pulling the manufacturer from computer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Pulling the manufacturer from computer

#16 Post by gymiv » 11 Jul 2012 10:03

this will work
@echo off
cls
For /F "skip=1 tokens=1" %%A IN ('WMIC csproduct get vendor') DO echo %%A
pause

but it will not work with the set statement so i can use the if statement

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Pulling the manufacturer from computer

#17 Post by foxidrive » 11 Jul 2012 10:30

In Win7 there is a trailing crlf that wipes the machine variable.

This should work in all OS

for /f "skip=1 delims=" %%a in ('WMIC csproduct get vendor') do if not defined machine set "machine=%%a"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Pulling the manufacturer from computer

#18 Post by foxidrive » 11 Jul 2012 10:35

And this will work to find dell in any machine vendor string

Code: Select all

@echo off
set "machine="
for /f "delims=" %%a in ('WMIC csproduct get vendor ^|find /i "dell" ') set "machine=%%a"

If defined machine (
echo it's a Dell "%machine%"
) else (
echo it wasn't a Dell
)


gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Pulling the manufacturer from computer

#19 Post by gymiv » 11 Jul 2012 10:40

That seems to have worked. Thanks again everyone. Nice to simplify the batch. Here is final code and results.

REM @ECHO OFF
for /f "skip=1 tokens=1" %%a in ('WMIC csproduct get vendor') do if not defined machine set "machine=%%a"
ECHO Computer model: "%machine%"

IF %machine%==Dell (
GOTO :setup
) ELSE (
GOTO :end
)


:setup
echo success
pause > nul
GOTO :eof


:end
echo not yet
pause > nul
GOTO :eof

C:\Users\JimT\Desktop>REM @ECHO OFF

C:\Users\JimT\Desktop>for /F "skip=1 tokens=1" %a in ('WMIC csproduct get vendor
') do if not defined machine set "machine=%a"

C:\Users\JimT\Desktop>if not defined machine set "machine=Dell"

" \Users\JimT\Desktop>if not defined machine set "machine=

C:\Users\JimT\Desktop>ECHO Computer model: "Dell"
Computer model: "Dell"

C:\Users\JimT\Desktop>IF Dell == Dell (GOTO :setup ) ELSE (GOTO :end )

C:\Users\JimT\Desktop>echo success
success

C:\Users\JimT\Desktop>pause 1>nul

Post Reply