1

How can I programatically check that I am running Windows 8.1 using cmd.exe or PowerShell?

3 Answers 3

4

Powershell

get-wmiobject win32_operatingsystem will return several properties you can use to check the OS.

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 
Sign up to request clarification or add additional context in comments.

2 Comments

Interesting that we need to use win32_operatingsystem on a 64bit operating system.
The class-names wasn't changed due to compatibility reasons. Win64_* names for 64bit os would just add complexity without giving any benefits.
2

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 

Comments

2

Another method using PowerShell:

(Get-Command -Name $env:windir\system32\ntoskrnl.exe).FileVersionInfo.FileVersion -match '6.3.9600'; 

This command returns $true or $false. To be honest, alroc's is the ideal solution, in my opinion. This is just an alternative.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.