我想创建一个批处理文件,它将执行以下操作:检查正在运行的操作系统是否为Windows.如果它应该打印,Hello. Im win 10
否则应该打印其他消息.如果条件怎么办呢?
伪代码:
if OS == Win10 then echo Hello im win 10 else echo I am another os
Vertexwahn.. 18
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
Stephan.. 5
如果您想更详细一点:
for /f "tokens=2 delims=," %%i in ('wmic os get caption^,version /format:csv') do set os=%%i echo Hello, I am %os%
或只是为了满足您的要求:
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
确保您所需的字符串不是最后一个标记,它包含丑陋的wmic行结尾)
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
如果您想更详细一点:
for /f "tokens=2 delims=," %%i in ('wmic os get caption^,version /format:csv') do set os=%%i echo Hello, I am %os%
或只是为了满足您的要求:
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
确保您所需的字符串不是最后一个标记,它包含丑陋的wmic行结尾)