错误级别不同

时间:2015-06-29 13:18:32

标签: batch-file find findstr errorlevel

我一直在尝试编写这个批处理脚本。我想要它做的是打开msinfo.exe,然后使用wmic检查制造商&取决于制造商,它将打开制造商网站。以下是我所写的内容,但没有成功:

@echo off

start %windir%\System32\msinfo32.exe

if exist c:\BIOS.txt (
      start c:\BIOS.txt
) else (
      wmic /output:c:\BIOS.txt bios get smbiosbiosversion
)

:asus

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "asus" > NUL

if %errorlevel% equ 1 (
      %programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto dell
)

:dell

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "dell" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto gateway
)

:gateway

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "gateway" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto hp
)

:hp

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "hewlett-packard" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto lenovo
)

:lenovo

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "lenovo" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto samsung
)

:samsung

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "samsung" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto sony
)

:sony

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "sony" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto toshiba
)

:toshiba

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer | FINDSTR "toshiba" > NUL

if %errorlevel% equ 1 (
      "%programfiles%\Internet Explorer\iexplore.exe" **place support site here**
      goto exit
) else (
      goto exit
)

:exit

任何有助于我理解的帮助将不胜感激。我正在阅读的所有内容尝试只是没有让我得到结果。我已经阅读了有关errorlevel&的所有内容。我想这没有意义吗?

1 个答案:

答案 0 :(得分:0)

这不起作用,因为您使用FINDSTR将要搜索的输出重定向到文件。所以FINDSTR无需搜索。

删除/输出(如果你不需要其他文件)或者这样做:

wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer 
type C:\manufacturer.txt | FINDSTR "asus" 

在第一行中,您从wmic获取输出并将其发送到文件。 在第二行中,您将获取新创建的文件并将其发送到FINDSTR,然后FINDSTR将搜索您指定的元素。之后,您可以测试错误级别。

要改进批处理,可能有必要在临时目录中创建文本文件并在再次运行批处理之前删除它们。把它放在批处理的顶部是个好主意。因此,您可以确定如果wmic由于某种原因失败,则您不会处理旧数据。