如何从命令提示符或 PowerShell 获取 Windows 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42778858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Windows version from command prompt or from PowerShell
提问by Sandie
But is there a way to get the exact version string using command line output similar to the one mentioned in the image?
但是有没有办法使用类似于图像中提到的命令行输出来获取确切的版本字符串?
The attached is the output of "winver" command from run. PS: I am looking for a batch or PowerShell command.
附件是运行中“winver”命令的输出。PS:我正在寻找批处理或 PowerShell 命令。
There are some alternates available to get the Windows version like this PowerShell command:
有一些替代方法可用于获取 Windows 版本,例如此 PowerShell 命令:
[System.Environment]::OSVersion
回答by shameer1101
The following commands are is going to help you with that. If you need more information, just type in systeminfo:
以下命令将帮助您解决这个问题。如果您需要更多信息,只需输入systeminfo:
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
wmic os get Caption,CSDVersion /value
回答by Mariano Desanze
The ver
commandshows something like this:
该ver
命令显示如下内容:
> ver
Microsoft Windows [Versión 10.0.17134.228]
But in PowerShell (or Git Bash) you have to call it through the cmd
command:
但是在 PowerShell(或 Git Bash)中,您必须通过以下cmd
命令调用它:
> cmd /c ver
回答by knil4_crack
I found it somewhere, PowerShell:
我在某处找到了它,PowerShell:
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
回答by acadie_man
To add to @Bonifacio 's answer:
添加到@Bonifacio 的答案:
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ReleaseId
Would be even better, because it returns only the ReleaseId value, which you could then pipe to a file. Especially useful if you have several hosts to deal with.
会更好,因为它只返回 ReleaseId 值,然后您可以将其通过管道传输到文件。如果您要处理多个主机,则特别有用。
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ReleaseId > any_path\%COMPUTERNAME%_OS_Version.txt
回答by Bonifacio
With system information you can only get the build with that value and go to Google to get the respective version.
使用系统信息,您只能获取具有该值的构建并转到 Google 以获取相应版本。
However, one simple way is by searching the registry on the command line:
但是,一种简单的方法是在命令行上搜索注册表:
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr REG_SZ