如何查看Windows 10版本?编写批处理按版本区间判断是否安装x.exe
Hey there, let's tackle your two questions step by step:
Here are a few straightforward ways to check your Windows 10 version details:
- Via System Settings: Open Settings → System → About, then look under the Windows specifications section. You'll find both the version number (e.g., 1607) and the internal build number (e.g., 14393) here.
- Using Command Prompt: Press Win+R, type
cmdand hit Enter. You can either runwinver(a pop-up window will show your full version info) or executesysteminfo | findstr /B /C:"OS Version"to get the details directly in the command line. - Through Registry Editor: Press Win+R, type
regeditto launch the registry. Navigate toHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion, then check theReleaseId(for version labels like 1607) andCurrentBuild(for build numbers like 14393) values.
Based on your requirement — install x.exe only if the Windows 10 version is between 1607 (Redstone 1) and RS3 (1709, before RS4), and skip installation for RS4 and later — we can use the internal build number for reliable detection, since build numbers are unique and increment consistently with each version update.
First, here's the version-to-build mapping you provided for reference:
threshold 1 1507 10240、threshold 2 1511 10586、redstone 1 1607 14393、redstone 2 1703 15063、redstone 3 1709 16299、redstone 4 1803 17134、redstone 5 1809 17650
We need to check if the build number falls between 14393 (1607) and 16299 (1709, inclusive). Here's the batch script to implement this logic:
@echo off setlocal enabledelayedexpansion :: Retrieve the Windows internal build number for /f "tokens=2 delims==" %%a in ('wmic os get buildnumber /value') do ( set "BuildNumber=%%a" ) :: Remove any extra spaces from the build number (WMIC output may have trailing spaces) set "BuildNumber=!BuildNumber: =!" :: Check if build number is within the target range (1607 to RS3) if !BuildNumber! geq 14393 if !BuildNumber! leq 16299 ( echo Current Windows version meets the criteria, starting installation of x.exe... start "" "x.exe" ) else ( echo Current Windows version is RS4 or newer, no need to install x.exe. ) pause
Script Breakdown:
wmic os get buildnumber /value: This command efficiently fetches the system's build number, which is more reliable for version detection than the human-readable release ID.- The
for /floop parses the WMIC output to extract the build number, and we strip any extra spaces to avoid comparison errors. - The double
ifstatement checks if the build number falls in our target range. If it does, the script launchesx.exe; otherwise, it prints a message stating installation isn't required. start "" "x.exe": This ensuresx.exelaunches correctly even if its file path contains spaces.
内容的提问来源于stack exchange,提问作者Ege Gökhan Gürkan

