Script to check Computer Model and Download BIOS File

1

0

I've just started working with WindowsScripting and would like some help figuring out how to write a Script that would check the model of a Computer and store the result in Variable in the Bat file.

Ultimately I am trying to automate checking the Computer model and download the correct BIOS file.

Here's what I've got so far.

start "" wmic computersystem get model > model.txt
if model == X
  start "" %windir%\explorer.exe "download url"
elseif model == Y
  start "" %windir%\explorer.exe "download url"
elseif model == Z
  start "" %windir%\explorer.exe "download url"

Any help is appreciated as I am new to this whole thing.

babsndeep

Posted 2016-01-12T18:01:59.393

Reputation: 11

To the close voters: 1/ question is not off-topic, batch files are on-topic for [su] 2/ it's perfectly clear what he is asking (see my answer) – DavidPostill – 2016-01-13T18:38:51.203

1Shouldn't be closed, but doesn't sound like the best idea... I wouldn't want to update my BIOS without carefully reading the release notes, and making absolutely 100% sure I get the correct update file. Most BIOS update info I've read (from the manufacturers) say "If you don't need it, and if it ain't broke, don't fix it" – Xen2050 – 2016-01-16T19:36:50.747

Two people have voted to close this, but I can't see why. The question is clear: OP wants to get the computer model and branch on it. – Ben N – 2016-01-21T16:20:18.457

Answers

1

How can I set the result of the following command to be a variable called model?

wmic computersystem get model

The output of this on my system is:

Model
VPCF22L1E

Note the extra blank line. I've used VPCF22L1E to test the batch file.

Use the following batch file (test.cmd):

@echo off
setlocal enableDelayedExpansion
for /f "usebackq skip=1" %%i in (`wmic computersystem get model`) do (
  set model=%%i
  goto :done
  )
:done
if [%model%]==[VPCF22L1E] start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "download url for VPCF22L1E"
if [%model%]==[Y] start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "download url for Y"
if [%model%]==[Z] start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "download url for Z"
endlocal

Notes:

  • skip=1 is used to skip the wmic header line.
  • goto :done is use to skip the wmic extra blank line.
  • Edit the if lines as appropriate.

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • for /f - Loop command against the results of another command.
  • if - Conditionally perform a command.
  • set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
  • start - Start a program, command or batch script (opens in a new window).
  • wmic - Windows Management Instrumentation Command.

DavidPostill

Posted 2016-01-12T18:01:59.393

Reputation: 118 938

Thank you David! I really appreciate the help and the fact that you not only explained what you did but also provided further reading material! Thank you very much! – babsndeep – 2016-01-14T01:12:57.370

@babsndeep Do you need more help? If this answer was helpful to you and answered your question, please don't forget to accept that answer. Also see Why is voting important?

– DavidPostill – 2016-01-14T08:44:21.470

Hey David, Yes! what you provided was very helpful, Sorry I didn't know about the Voting!.However, I was working on the rest of the script today and tested this code alone in a separate file, and couldn't get it to work. @echo off setlocal enableDelayedExpansion for /f "usebackq skip=1" %%i in ('wmic computersystem get model') do ( set model=%%i goto :done ) :done if [%model%]==[Latitude E6320] start "" %windir%\explorer.exe http://downloads.dell.com/FOLDER03279939M/1/E6330A15.exe endlocal

– babsndeep – 2016-01-14T18:00:21.233

The output of 'wmic get computersystem model' is: Model Latitude E6320 – babsndeep – 2016-01-14T18:04:07.907

That should work. What is the output from wmic computersystem get model on your PC? – DavidPostill – 2016-01-14T18:04:31.877

Can you add echo %model% after the set and tell me what it outputs? – DavidPostill – 2016-01-14T18:06:46.373

Model (on first line) Latitude E6320 (on second line) When I run 'wmic get computersystem model' in cmd directly – babsndeep – 2016-01-14T18:06:47.667

It could be because of the space in the model name. Try changing usebackq skip=1 to usebackq skip=1 tokens=* – DavidPostill – 2016-01-14T18:09:27.610

No Change with tokens=* addition – babsndeep – 2016-01-14T18:12:40.937

Please add the echo %model% as I requested. – DavidPostill – 2016-01-14T18:13:47.447

I did add echo %model%, the cmd window flashes really quick, I am not unable to read anything from it. – babsndeep – 2016-01-14T18:15:32.587

Add pause as the next line – DavidPostill – 2016-01-14T18:16:09.170

Note, I couldn't get it to work with %windir%\explorer.exe thats why I changed the batch file to use %ProgramFiles%\Internet Explorer\iexplore.exe instead. – DavidPostill – 2016-01-14T18:19:06.063

%ProgramFiles%\Internet Explorer \iexplorer.exe doesn't work for me, even when run as a standalone command in cmd window, %windir%\explorer.exe does however work when run alone in the cmd window. – babsndeep – 2016-01-14T23:01:54.620

<shrug> I've done my best. It works here as described on Windows 7. Don't forget to add quotes around "%ProgramFiles%\Internet Explorer\iexplore.exe" as it contains a space. – DavidPostill – 2016-01-14T23:04:47.380