简体   繁体   English

批量获取确切的Windows版本

[英]Get exact Windows build in batch

I need to get the exact Windows build of my os in a batch-file and I want to store it as a variable. 我需要在批处理文件中获取操作系统的确切Windows版本,并且要将其存储为变量。 I need the full build like 14393.3144 (displayed if winver is used), because I want to check if an update was successfully installed. 我需要完整的版本,如14393.3144(如果使用winver则显示),因为我想检查更新是否已成功安装。 I've already tryed using wmic os get buildnumber but it only returns 14393. Additionally to this I thought about reading the Windows Update log but creating it with the powershell command Get-WindowsUpdateLog simply takes to much time and isn't reliable enough. 我已经尝试过使用wmic os get buildnumber但是它只会返回14393。此外,我还想阅读Windows Update日志,但是使用powershell命令Get-WindowsUpdateLog创建它会花费很多时间,并且不够可靠。

Here's an example which retrieves the full version using : 这是一个使用检索完整版本的示例:

@Set "OSVer="
@For /F EOL^=V %%A In ('"%__AppDir__%wbem\WMIC.exe" OS Get Version 2^>NUL')Do @For %%B In (%%A)Do @Set "OSVer=%%B"
@Set OSVer 2>NUL&&Pause

On a test machine, this has just returned 10.0.18362 在测试机上,它刚刚返回10.0.18362


You could of course use the internal Ver command, (which technically returns the version of cmd.exe , not the OS) : 您当然可以使用内部Ver命令(从技术上讲它返回cmd.exe的版本,而不是操作系统)

@Set "OSVer="
@For /F Delims^=] %%A In ('Ver')Do @For %%B In (%%A)Do @Set "OSVer=%%B"
@Set OSVer 2>NUL&&Pause

On a test machine, this has just returned 10.0.18362.295 在测试机上,它刚刚返回10.0.18362.295


You could of course try parsing the registry for the information too: 您当然也可以尝试解析注册表以获取信息:

 @Set "RKey=HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" @For /F Tokens^=2* %%A In ('^""%__AppDir__%reg.exe" Query "%RKey%" /V CurrentBuildNumber^" 2^>NUL')Do @Set "NUM=%%B" @For /F Tokens^=2* %%A In ('^""%__AppDir__%reg.exe" Query "%RKey%" /V UBR^" 2^>NUL')Do @Set /A UBR=%%B 2>NUL @Echo(%NUM%.%UBR%&Pause 

On a test machine, this has just returned 18362.295 在测试机上,它刚刚返回18362.295



Alternatively, take a look at this Super User question and answers. 另外,请查看超级用户的问题和解答。

Use ver . 使用ver The output is like what you want. 输出就像您想要的。

> C:\Users\user>ver
> 
> Microsoft Windows [Version 10.0.17763.678]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM