当前位置:  开发笔记 > 开发工具 > 正文

批处理文件:检查操作系统是否为Windows 10

如何解决《批处理文件:检查操作系统是否为Windows10》经验,为你挑选了2个好方法。

我想创建一个批处理文件,它将执行以下操作:检查正在运行的操作系统是否为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行结尾)



1> Vertexwahn..:
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



2> Stephan..:

如果您想更详细一点:

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行结尾)

推荐阅读
跟我搞对象吧
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有