View unanswered posts | View active topics It is currently 28 Nov 2014 10:47



Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Pulling the manufacturer from computer 
Author Message

Joined: 10 Jul 2012 13:47
Posts: 38
Post Pulling the manufacturer from computer
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


10 Jul 2012 14:03
Profile

Joined: 23 Dec 2011 13:59
Posts: 2023
Post Re: Pulling the manufacturer from computer
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.


10 Jul 2012 14:50
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
Thanks i changed that but it had no effect


10 Jul 2012 14:58
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
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


10 Jul 2012 15:12
Profile

Joined: 23 Dec 2011 13:59
Posts: 2023
Post Re: Pulling the manufacturer from computer
You didn't change the set statement.


10 Jul 2012 16:08
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
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


10 Jul 2012 16:14
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
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 . . .


10 Jul 2012 16:16
Profile
Online

Joined: 10 Feb 2012 02:20
Posts: 4424
Post Re: Pulling the manufacturer from computer
@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
)


10 Jul 2012 21:35
Profile
Expert

Joined: 13 Jan 2012 21:24
Posts: 441
Post Re: Pulling the manufacturer from computer
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


10 Jul 2012 23:26
Profile

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post Re: Pulling the manufacturer from computer
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

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


And If you add
Code:
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:
@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.


11 Jul 2012 02:46
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
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


11 Jul 2012 07:47
Profile

Joined: 23 Dec 2011 13:59
Posts: 2023
Post Re: Pulling the manufacturer from computer
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.


11 Jul 2012 07:56
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
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>


11 Jul 2012 09:35
Profile

Joined: 10 Jul 2012 13:47
Posts: 38
Post Re: Pulling the manufacturer from computer
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>


11 Jul 2012 09:39
Profile

Joined: 23 Dec 2011 13:59
Posts: 2023
Post Re: Pulling the manufacturer from computer
Don't know what to tell you. It works fine on my computer.


11 Jul 2012 09:51
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] 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 © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.