KOMPX.COM or COMPMISCELLANEA.COM   

Get OS name in Windows Command Prompt

Getting the operating system name in Windows Command Prompt by means of SYSTEMINFO, FINDSTR and FOR commands:


FOR /F "TOKENS=2,* DELIMS= " %G IN ('SYSTEMINFO ^| FINDSTR /B /C:"OS Name"') DO @ ECHO %H

Code for .BAT file


@ECHO OFF
FOR /F "TOKENS=2,* DELIMS= " %%G IN ('SYSTEMINFO ^| FINDSTR /B /C:"OS Name"') DO (
	ECHO %%H
)

Links

  1. How to get last n tokens from string using "FOR /F" in batch file stackoverflow.com/questions/35477290/how-to-get-last-n-tokens-from-string-using-for-f-in-batch-file#answer-35477800
  2. how do I pipe to the "for" command? superuser.com/questions/234043/how-do-i-pipe-to-the-for-command#answer-234052
  3. What version of Windows am I running? learn.microsoft.com/en-us/windows/client-management/client-tools/windows-version-search
Operating systems
More