[英]How can I programatically check that I am running Windows 8.1?
如何使用cmd.exe或PowerShell以编程方式检查我是否正在运行Windows 8.1?
get-wmiobject win32_operatingsystem
will return several properties you can use to check the OS. get-wmiobject win32_operatingsystem
将返回几个可用于检查操作系统的属性。
get-wmiobject win32_operatingsystem|select-object name,caption,buildnumber,version|format-list
name : Microsoft Windows 8.1 Enterprise|C:\WINDOWS|\Device\Harddisk0\Partition2
caption : Microsoft Windows 8.1 Enterprise
buildnumber : 9600
version : 6.3.9600
CMD CMD
wmic os get caption /value|find "="
to put it into a variable: 将其放入变量中:
for /f %%i in ('wmic os get caption /value^|find "="') do set version=%%i
Another method using PowerShell: 使用PowerShell的另一种方法:
(Get-Command -Name $env:windir\system32\ntoskrnl.exe).FileVersionInfo.FileVersion -match '6.3.9600';
This command returns $true
or $false
. 此命令返回
$true
或$false
。 To be honest, alroc's is the ideal solution, in my opinion. 老实说,我认为alroc是理想的解决方案。 This is just an alternative.
这只是一种选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.