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

Pulling the manufacturer from computer

#1 Post by gymiv » 10 Jul 2012 14:03

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

Squashman
Expert
Posts: 3666
Joined: 23 Dec 2011 13:59

Re: Pulling the manufacturer from computer

#2 Post by Squashman » 10 Jul 2012 14:50

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.

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

Re: Pulling the manufacturer from computer

#3 Post by gymiv » 10 Jul 2012 14:58

Thanks i changed that but it had no effect

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

Re: Pulling the manufacturer from computer

#4 Post by gymiv » 10 Jul 2012 15:12

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

Squashman
Expert
Posts: 3666
Joined: 23 Dec 2011 13:59

Re: Pulling the manufacturer from computer

#5 Post by Squashman » 10 Jul 2012 16:08

You didn't change the set statement.

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

Re: Pulling the manufacturer from computer

#6 Post by gymiv » 10 Jul 2012 16:14

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

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

Re: Pulling the manufacturer from computer

#7 Post by gymiv » 10 Jul 2012 16:16

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 . . .

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

Re: Pulling the manufacturer from computer

#8 Post by foxidrive » 10 Jul 2012 21:35

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

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Pulling the manufacturer from computer

#9 Post by Liviu » 10 Jul 2012 23:26

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

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Pulling the manufacturer from computer

#10 Post by abc0502 » 11 Jul 2012 02:46

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.

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

Re: Pulling the manufacturer from computer

#11 Post by gymiv » 11 Jul 2012 07:47

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

Squashman
Expert
Posts: 3666
Joined: 23 Dec 2011 13:59

Re: Pulling the manufacturer from computer

#12 Post by Squashman » 11 Jul 2012 07:56

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.

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

Re: Pulling the manufacturer from computer

#13 Post by gymiv » 11 Jul 2012 09:35

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>

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

Re: Pulling the manufacturer from computer

#14 Post by gymiv » 11 Jul 2012 09:39

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>

Squashman
Expert
Posts: 3666
Joined: 23 Dec 2011 13:59

Re: Pulling the manufacturer from computer

#15 Post by Squashman » 11 Jul 2012 09:51

Don't know what to tell you. It works fine on my computer.

Post Reply