I want to search for the string "virtual" in "system model" attribute of 'sysinfo' command. The command should be successful if 'virtual' is found in the 'system model: -------------------------' i.e. output of the systeminfo. It should not search for 'virtual' in whole output of systeminfo command but should do in system model attribute only. For example the command
systeminfo | findstr /i "system model"
I will get something like
System Model: HP Compaq dc7800p Small Form Factor
in the above line of the output i want to search for string virtual, and want to manipulate using errorlevel. So please help me to do this.
Following is the one I tried which was not correct. Or help me if i can use regular expressions
systeminfo | findstr /i /R "system model: virtual machine" > nul
if %errorlevel% == 0 (
echo virtual machine
) ELSE (
echo physical machine
)
Thanks in advance
By default, this command is set to ctrl+shift+f . // Press ctrl+shift+f to open the search box { "command": "find", "keys": "ctrl+shift+f" }, For example, you can change "ctrl+shift+f" to "ctrl+f", so when typing ctrl+f , the search dialog will open.
Specifies the text string to find. Specifies a file or files to search. If a pathname is not specified, FIND searches the text typed at the prompt or piped from another command.
Try this:
systeminfo | findstr /I /B /C:"system model" | findstr /I "virtual"
if %errorlevel% == 0 (
echo virtual machine
) else (
echo real machine
)
I've tested in on a real and virtual system and it works fine on WinXp and Win7.
Note that the system model
string is only used in English Windows versions. Windows versions in other languages will use a different names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With