[英]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 wmic : 这是一个使用wmic检索完整版本的示例:
@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
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
@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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.