• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Batch file advice for detecting hardware

We use a batch file to execute a variety of repetitive commands on newly-built computers. There are two points in this batch file where WMI commands are used to (1) detect the presence of a specific SSD manufacturer and (2) detect the model name of the computer. I found the WMI commands that would display the needed output, but I think the approach could use some review.

The detection of the model goes works fine:

FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Name /VALUE ^| FIND /I "Name="') DO SET machine=%%A
FOR /F "tokens=1 delims= " %%A IN ('echo %machine%') DO SET machine=%%A
ECHO Computer model: %machine%
SET machine2=%machine: =%
ECHO Configuring settings and installing applications per platform type...
IF /I "%machine2%" == "Latitude" GOTO NOTEBOOK
IF /I "%machine2%" == "Precision" GOTO WORKSTATION
IF /I "%machine2%" == "Optiplex" GOTO DESKTOP

Open in new window


PROBLEM AREA:

I tried using the same approach to detect if a computer had an Intel SSD installed using this:

FOR /F "tokens=2 delims==" %%A IN ('WMIC diskdrive get model /value ^| FIND /I "Model="') DO SET model=%%A
FOR /F "tokens=1 delims= " %%A IN ('echo %model%') DO SET model=%%A
ECHO SSD Manufacturer: %model%
SET model2=%model: =%
IF /I "%model2%" == "INTEL" GOTO INTELSSD

Open in new window


Even if the computer has a non-Intel SSD it still will proceed to the designated step of installing the Intel SSD Toolbox.

Is there a better way to structure this so I do not have to list every that might be detected so that it will skip the installation of the Intel SSD Toolbox?
0
hufftw
Asked:
hufftw
  • 2
2 Solutions
 
oBdACommented:
You can just skip the toolbox installation if the manufacturer is not Intel (and shorten the code):
FOR /F "tokens=2 delims== " %%A IN ('WMIC diskdrive get model /value ^| FIND /I "Model="') DO SET model=%%A
ECHO SSD Manufacturer: '%model%'
if /i not "%model%" == "INTEL" GOTO EndIntelSSDToolbox
setup.exe ...
:EndIntelSSDToolbox

Open in new window

0
 
oBdACommented:
As far as the first part is concerned, you could do it like that, including a check for unsupported hardware, just in case:
FOR /F "tokens=2 delims== " %%A IN ('WMIC csproduct GET Name /VALUE ^| FIND /I "Name="') DO SET machine=%%A
ECHO Computer model: '%machine%'
ECHO Configuring settings and installing applications per platform type...
IF /I "%machine%" == "Precision" GOTO WORKSTATION
IF /I "%machine%" == "Optiplex"  GOTO DESKTOP
IF /I "%machine%" == "Latitude"  GOTO NOTEBOOK
echo Unknown machine '%machine%' found!
goto :eof
:WORKSTATION
...
goto EndPlatform
:DESKTOP
...
goto EndPlatform
:NOTEBOOK
...
goto EndPlatform
:EndPlatform

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now