在批处理文件中获取 Windows 版本 [英] Get Windows version in a batch file
本文介绍了在批处理文件中获取 Windows 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用批处理文件获取操作系统版本.我在网上看过很多例子,很多都使用了这样的代码:
I need to get the OS version with a batch file. I 've seen a lot of examples online, many uses something like this code:
@echo off
ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp
if not exist %SystemRoot%system32systeminfo.exe goto warnthenexit
systeminfo | find "OS Name" > %TEMP%osname.txt
FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%osname.txt) DO set vers=%%i
echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7
echo %vers% | find "Windows Vista" > nul
if %ERRORLEVEL% == 0 goto ver_vista
goto warnthenexit
:ver_7
:Run Windows 7 specific commands here.
echo Windows 7
goto exit
:ver_vista
:Run Windows Vista specific commands here.
echo Windows Vista
goto exit
:ver_xp
:Run Windows XP specific commands here.
echo Windows XP
goto exit
:warnthenexit
echo Machine undetermined.
:exit
问题是当我在 Vista 或 Windows 7 上执行此操作时,我收到了消息
The problem is when I execute this on Vista or Windows 7 I get the message
机器未确定
还有其他方法可以做我想做的事吗?
Is there any other way to do what I want?
推荐答案
你试过使用 wmic
命令吗?
Have you tried using the wmic
commands?
试试wmic os 获取版本
这将在命令行中为您提供版本号,然后您只需集成到批处理文件中.
This will give you the version number in a command line, then you just need to integrate into the batch file.
这篇关于在批处理文件中获取 Windows 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文