我想在'sysinfo'命令的"系统型号"属性中搜索字符串"虚拟"。如果在系统信息的输出'系统型号:-------------------------' 中找到了'虚拟',则该命令将成功。它不应该在整个systeminfo命令的输出中搜索'虚拟',而应该只在系统型号属性中进行搜索。
例如,该命令
systeminfo | findstr /i "system model"
我将获得类似的东西
System Model: HP Compaq dc7800p Small Form Factor
在输出的上述行中,我想搜索字符串“virtual”,并希望使用errorlevel进行操作。请帮助我完成这个任务。
以下是我尝试过但不正确的代码。或者请告诉我是否可以使用正则表达式。
systeminfo | findstr /i /R "system model: virtual machine" > nul
if %errorlevel% == 0 (
echo virtual machine
) ELSE (
echo physical machine
)
提前感谢您
findstr /i /b /C:"system model"
(在这种特殊情况下没有问题,因为systeminfo
中没有以“Model”开头的行)。 - Stephan