Пакет Windows - компьютерная система wmic get model - несколько моделей - PullRequest
0 голосов
/ 04 мая 2018

У меня есть вопрос, похожий на Пакет Windows: запросить wmic computerystem получить модель, если равно true, продолжить с пакетом Windows

У меня есть пакетный файл, который использует wmic для получения номера модели системы, и мне нужно будет запустить скрипт на основе номера модели

Вот мой сценарий

REM @echo off
setlocal enableextensions disabledelayedexpansion

for /f "tokens=2 delims==" %%a in (
    'wmic computersystem get model /value'
) do for /f "delims=" %%b in ("%%~a") do for %%m in (
    "HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620 Quad Core TC" "HP t630 Thin Client"
) do if /i "%%~b"=="%%~m" (
    set "model=%%~m"
    goto start
)

echo un-compatible system
goto :eof
:start
echo Start of script for model [%model%]
if [%model%]==[t520] start "" "C:\SWSetup\APP\Scripts\t520.bat" "C:\SWSetup\APP\Scripts\t520-wmi.bat"
if [%model%]==[t610] start "" "C:\SWSetup\APP\Scripts\t610.bat" "C:\SWSetup\APP\Scripts\t610-wmi.bat"
if [%model%]==[t620] start "" "C:\SWSetup\APP\Scripts\t620.bat" "C:\SWSetup\APP\Scripts\t620-wmi.bat"
if [%model%]==[t630] start "" "C:\SWSetup\APP\Scripts\t630.bat" "C:\SWSetup\APP\Scripts\t630-wmi.bat"

Вот вывод окна cmd

C:\SWSetup\APP\Scripts>setlocal enableextensions disabledelayedexpansion

C:\SWSetup\APP\Scripts>for /F "tokens=2 delims==" %a in ('wmic computersystem get model /value') do for /F "delims=" %b in ("%~a") do for %m in ("HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620 Quad Core TC" "HP t630 Thin Client") do if /I "%~b" == "%~m" (set "model=%~m"
goto start
)

") do for %m in ("HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620Quad Core TC" "HP t630 Thin Client") do if /I "%~b" == "%~m" (set "model=%~m"
goto start
)

C:\SWSetup\APP\Scripts>for %m in ("HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620 Quad Core TC" "HP t630 Thin Client") do if /I "HP t520 Flexible Series TC" == "%~m" (set "model=%~m"
goto start
)

C:\SWSetup\APP\Scripts>if /I "HP t520 Flexible Series TC" == "HP t520 Flexible Series TC" (set "model=HP t520 Flexible Series TC" 
goto start
)

C:\SWSetup\APP\Scripts>echo Start of script for model [HP t520 Flexible Series TC] Start of script for model [HP t520 Flexible Series TC] t520 was unexpected at this time.

C:\SWSetup\APP\Scripts>if [HP t520 Flexible Series TC]==[t520] start "" "C:\SWSetup\APP\Scripts\t520.bat" "C:\SWSetup\APP\Scripts\t520-wmi.bat"

Что мне здесь не хватает?

Ответы [ 2 ]

0 голосов
/ 05 мая 2018
@echo off
setlocal enableextensions disabledelayedexpansion
Set "Model="
for /f "tokens=2 delims==" %%a in (
    'wmic computersystem get model /value'
) do for /f "delims=" %%b in ("%%~a") do Set "Model=%%b"

If not defined Model (Echo Can't get Model&Pause&Exit/B 1)

Echo:%Model%|findstr /i "t520 t620 t630 t640" >Nul 2>&1 ||(Echo None of the specified models&Exit/B 1)

for %%m in (t520 t620 t630 t640
  ) do @Echo:%Model%|findstr /i "%%m"  >NUL 2>&1 && (
    start "" "C:\SWSetup\APP\Scripts\%%m.bat" "C:\SWSetup\APP\Scripts\%%m-wmi.bat"
)
0 голосов
/ 05 мая 2018

Вот непроверенная идея.

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
CD /D "C:\SWSetup\APP\Scripts" 2>Nul || Exit /B
Set "Model="
For /F "Tokens=2" %%A In ('WMIC ComputerSystem Get Model^|Find "HP"'
) Do Set "Model=%%A"
If Exist "%Model%.bat" If Exist "%Model%-wmi.bat" (
        Echo Start of script for model [%Model%]
        Call "%Model%.bat" "%Model%-wmi.bat")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...