Page 1 of 2

Pulling the manufacturer from computer

Posted: 10 Jul 2012 14:03
by gymiv
I am writing a batch file to look for just Dell computers. The problem is that the value this will return on Dell computers can be Dell Inc., Dell or whatever I need to make it look for just the word Dell. Since I believe that Dell will always be the first four characters I am parsing the 1st variable four the first 4 characters. I have almost completed the part that identifies the manufacturer and then uses a goto command to send it to the correct place in the batch. It errors out at the IF %_prefix%=Dell on the 7th line with Dell not expected yet. I would even be willing to entertain a different way of doing it but i am very curios why this is not working. Everything above that works fine. Can someone help solve this puzzle?
Thanks in advance for your help.

@ECHO OFF
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Vendor /VALUE ^| FIND /I "Vendor="') DO SET machine=%%A
ECHO Computer model: "%machine%"

set _prefix==%machine:~0,4%
echo %_prefix%
IF %_prefix%=Dell (
goto setup
) ELSE (
goto end
)


:setup
echo success

:end
echo not yet
pause

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 14:50
by Squashman
You need to use two equals symbols with your IF comparison. You should also look a using the /I switch.

Edit: Just noticed your set statement is using two equal symbols when you only need one.

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 14:58
by gymiv
Thanks i changed that but it had no effect

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 15:12
by gymiv
Here are some small changes i have made to the code the results in the DOS screen are shown below that. It seems that now there is something wrong with the ELSE statement. It shouldn't be showing both the last 2 echo's just one or the other. Or is this the way it should come out?
rem @ECHO OFF
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Vendor /VALUE ^| FIND /I "Vendor="') DO SET machine=%%A
ECHO Computer model: "%machine%"

set prefix==%machine:~0,4%
IF %prefix%==Dell (
GOTO setup
) ELSE (
GOTO end
)


:setup
echo success

:end
echo not yet
pause

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

C:\Users\JimT\Desktop>FOR /F "tokens=2 delims==" %A IN ('WMIC csproduct GET Vend
or /VALUE | FIND /I "Vendor="') DO SET machine=%A

:\Users\JimT\Desktop>SET machine=Dell Inc.

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

C:\Users\JimT\Desktop>set prefix==Dell

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

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

C:\Users\JimT\Desktop>echo not yet
not yet

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 16:08
by Squashman
You didn't change the set statement.

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 16:14
by gymiv
Oops it slipped back in here are the new results
rem @ECHO OFF
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Vendor /VALUE ^| FIND /I "Vendor="') DO SET machine=%%A
ECHO Computer model: "%machine%"

set prefix=%machine:~0,4%
ECHO %prefix%
IF %prefix%==Dell (
GOTO setup
) ELSE (
GOTO end
)


:setup
echo success

:end
echo not yet
pause > nul


C:\Users\JimT\Documents\scripts>rem @ECHO OFF

C:\Users\JimT\Documents\scripts>FOR /F "tokens=2 delims==" %A IN ('WMIC csproduc
t GET Vendor /VALUE | FIND /I "Vendor="') DO SET machine=%A

:\Users\JimT\Documents\scripts>SET machine=Dell Inc.

C:\Users\JimT\Documents\scripts>ECHO Computer model: "Dell Inc."
Computer model: "Dell Inc."

C:\Users\JimT\Documents\scripts>set prefix=Dell

C:\Users\JimT\Documents\scripts>ECHO Dell
Dell

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


C:\Users\JimT\Documents\scripts>echo success
success

C:\Users\JimT\Documents\scripts>echo not yet
not yet

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 16:16
by gymiv
Without the pause > nul
C:\Users\JimT\Documents\scripts>FOR /F "tokens=2 delims==" %A IN ('WMIC csproduc
t GET Vendor /VALUE | FIND /I "Vendor="') DO SET machine=%A

:\Users\JimT\Documents\scripts>SET machine=Dell Inc.

C:\Users\JimT\Documents\scripts>ECHO Computer model: "Dell Inc."
Computer model: "Dell Inc."

C:\Users\JimT\Documents\scripts>set prefix=Dell

C:\Users\JimT\Documents\scripts>ECHO Dell
Dell

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


C:\Users\JimT\Documents\scripts>echo success
success

C:\Users\JimT\Documents\scripts>echo not yet
not yet

C:\Users\JimT\Documents\scripts>pause
Press any key to continue . . .

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 21:35
by foxidrive
@ECHO OFF
set "machine="
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Vendor /VALUE ^| FIND /I "Vendor=" ^| find /i "Dell" ') DO set machine=%%a

If defined machine (
echo it's a Dell
) else (
echo it ain't a Dell
)

Re: Pulling the manufacturer from computer

Posted: 10 Jul 2012 23:26
by Liviu
gymiv wrote:It seems that now there is something wrong with the ELSE statement. It shouldn't be showing both the last 2 echo's just one or the other. Or is this the way it should come out?
Nothing wrong with ELSE and, yes, that's what's supposed to come out.

You probably want a "goto :eof" or similar after "echo success", otherwise it's simply falling through and continuing to run the ":end" portion.

Liviu

Re: Pulling the manufacturer from computer

Posted: 11 Jul 2012 02:46
by abc0502
why you go through all this troubles why don't you just use "WMIC csproduct get vendor"
and skip the first line in a For loop and then take the first token

FOR /F "skip=1 tokens=1" %%A in ('WMIC csproduct get vendor') Do Set Machine=%%A


And If you add

Code: Select all

Echo %Machine%

at the end of the code and a pause command you get the vendor name
I tested on my PC and my vendor is gigabyte and it work fine

Here is a Test batch:

Code: Select all

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

and one ore thing in all functions you make ":end" and ":setup" like liviu said must end with goto EOF to prevent the batch from continuing to the other functions
and test your code from a batch not from the command line.

Re: Pulling the manufacturer from computer

Posted: 11 Jul 2012 07:47
by gymiv
In answer to your question, you have to remember when you do a WMIC csproduct GET Vendor you could get Dell Inc, or just Dell or however they want to display it. However it is a pretty safe bet that the first 4 letters are going to be Dell. That is why I need to parse the variable from the WMIC csproduct GET Vendor command. Otherwise if i get Dell Inc. for the IF command then it goes to the wrong section. I did get it working fine the piece I had forgot was the :eof. Thanks all. Here is my final code.

@ECHO OFF
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Vendor /VALUE ^| FIND /I "Vendor="') DO SET machine=%%A
ECHO Computer model: "%machine%"

set prefix=%machine:~0,4%
ECHO %prefix%
IF %prefix%==Dell (
GOTO setup
) ELSE (
GOTO end
)


:setup
echo success
pause > nul
GOTO :eof


:end
echo not yet
pause > nul
GOTO :eof

Re: Pulling the manufacturer from computer

Posted: 11 Jul 2012 07:56
by Squashman
gymiv you are missing the point of the previous script. FOR LOOPS delimit the output using spaces by default. If you use ABC's code it should always output as Dell because it will delimit by a space and remove the "Inc."

Test his FOR LOOP.

Re: Pulling the manufacturer from computer

Posted: 11 Jul 2012 09:35
by gymiv
Tested this and could not get his command to work. Here is the code and result. Do i need to put the find statement back in?

REM @ECHO OFF
FOR /F "tokens=1" %%A in ('WMIC csproduct get vendor') Do 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 "tokens=1" %A in ('WMIC csproduct get vendor') Do S
et Machine=%A

C:\Users\JimT\Desktop>Set Machine=Vendor

C:\Users\JimT\Desktop>Set Machine=Dell

:\Users\JimT\Desktop>Set Machine=

C:\Users\JimT\Desktop>ECHO Computer model: ""
Computer model: ""
( was unexpected at this time.
==Dell (\JimT\Desktop>IF
C:\Users\JimT\Desktop>

Re: Pulling the manufacturer from computer

Posted: 11 Jul 2012 09:39
by gymiv
Sorry left out the skip when i was testing it. Here is the code with the skip in it. Still no go

REM @ECHO OFF
FOR /F "skip=1 tokens=1" %%A in ('WMIC csproduct get vendor') Do 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 Set Machine=%A

C:\Users\JimT\Desktop>Set Machine=Dell

:\Users\JimT\Desktop>Set Machine=

C:\Users\JimT\Desktop>ECHO Computer model: ""
Computer model: ""
( was unexpected at this time.
==Dell (\JimT\Desktop>IF
C:\Users\JimT\Desktop>

Re: Pulling the manufacturer from computer

Posted: 11 Jul 2012 09:51
by Squashman
Don't know what to tell you. It works fine on my computer.