DosTips.com

A Forum all about DOS Batch
It is currently 11 Feb 2016 06:56

All times are UTC-06:00




Post new topic  Reply to topic  [ 19 posts ]  Go to page Previous 1 2
Author Message
PostPosted: 11 Jul 2012 10:03 
Offline

Joined: 10 Jul 2012 13:47
Posts: 38
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


Top
   
PostPosted: 11 Jul 2012 10:30 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5369
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"


Top
   
PostPosted: 11 Jul 2012 10:35 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5369
And this will work to find dell in any machine vendor string

Code:
@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
)



Top
   
PostPosted: 11 Jul 2012 10:40 
Offline

Joined: 10 Jul 2012 13:47
Posts: 38
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 19 posts ]  Go to page Previous 1 2

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited