Batch file: check if Windows 10 is

I want to create a batch file that performs the following operation: checks if Windows is running. If so, then print Hello. Im win 10 Hello. Im win 10 else should print another message. How can I do this if the condition?

pseudo code:

 if OS == Win10 then echo Hello im win 10 else echo I am another os 
+5
source share
3 answers
 setlocal for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j if "%version%" == "6.3" echo Windows 8.1 if "%version%" == "6.2" echo Windows 8. if "%version%" == "6.1" echo Windows 7. if "%version%" == "6.0" echo Windows Vista. if "%version%" == "10.0" echo Windows 10. echo %version% rem etc etc endlocal 
+11
source

if you want a little more detail:

 for /f "tokens=2 delims=," %%i in ('wmic os get caption^,version /format:csv') do set os=%%i echo Hello, I am %os% 

or just fit your requirements:

 for /f "tokens=2 delims=," %%i in ('wmic os get caption^,version /format:csv') do set os=%%i echo %os%|find " 10 ">nul &&echo Hello I'm Windows 10||echo I am another os 

( ,version ensures that your desired string is not the last token that contains this ugly wmic string)

+4
source

I improved the Vertexwahn script to support more versions of Windows:

 setlocal for /f "tokens=2 delims=[]" %%i in ('ver') do set VERSION=%%i for /f "tokens=2-3 delims=. " %%i in ("%VERSION%") do set VERSION=%%i.%%j if "%VERSION%" == "5.00" echo Windows 2000 if "%VERSION%" == "5.0" echo Windows 2000 if "%VERSION%" == "5.1" echo Windows XP if "%VERSION%" == "5.2" echo Windows Server 2003 if "%VERSION%" == "6.0" echo Windows Vista if "%VERSION%" == "6.1" echo Windows 7 if "%VERSION%" == "6.2" echo Windows 8 if "%VERSION%" == "6.3" echo Windows 8.1 if "%VERSION%" == "6.4" echo Windows 10 if "%VERSION%" == "10.0" echo Windows 10 echo %VERSION% endlocal 
0
source

Source: https://habr.com/ru/post/1238407/


All Articles