首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Errorlevel不同

Errorlevel不同
EN

Stack Overflow用户
提问于 2015-06-29 21:18:32
回答 1查看 132关注 0票数 0

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

代码语言:javascript
复制
@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的所有内容&我猜这是不合理的?

EN

回答 1

Stack Overflow用户

发布于 2015-06-29 21:25:40

这不会起作用,因为您通过使用FINDSTR将想要搜索的输出重定向到一个文件。所以FINDSTR没有什么可搜索的。

删除/output (如果您不需要将该文件用于其他用途)或执行以下操作:

代码语言:javascript
复制
wmic /output:c:\Manufacturer.txt Computersystem get Manufacturer 
type C:\manufacturer.txt | FINDSTR "asus" 

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31116795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档