How do I determine if my system is Windows 10 using the command line?
Is there a command to determine if I'm working on a Windows 10 system?
You can use wmic
.
The following command will return the Windows version.
wmic os get Caption | findstr /v Caption
Example output:
F:\test>wmic os get Caption | findstr /v Caption
Microsoft Windows 7 Home Premium
If you want a little more information, you can use the following batch file (GetOS.cmd), which will retrieve and display:
- Operating System Version
- Service Pack Major Version
- Architecture (64 or 32 bit)
@echo off
setlocal
setlocal enabledelayedexpansion
set _os=
set _sp=
rem use findstr to strip blank lines from wmic output
rem get OS
for /f "usebackq skip=1 tokens=3" %%i in (`wmic os get caption ^| findstr /r /v "^$"`) do (
set "_os=%%i"
)
rem get Service Pack
for /f "usebackq skip=1 tokens=*" %%i in (`wmic os get ServicePackMajorVersion ^| findstr /r /v "^$"`) do (
set "_sp=%%i"
)
rem get Architecture
for /f "usebackq skip=1 tokens=*" %%i in (`wmic OS get OSArchitecture ^| findstr /r /v "^$"`) do (
set "_bits=%%i"
)
echo Operating System Version: %_os%
echo Service Pack Major Version: %_sp%
echo Architecture: %_bits%
endlocal
The OS Version is stored in %_os
, Service Pack Major Version is stored in %_sp%
, and the Architecture is stored in %_bits%
.
Notes:
Not completely tested as I don't have all the OS and Service Pack combinations to test it with.
The
for
command retrieves only the 3rd part (token) of the OS. This will work for the desktop versions (if you want to distinguish Server 2008 from other versions you will need to find another solution).%_os
will be set to one of the following values:Server
,Vista
,7
,8
,8.1
or10
.
Example output:
F:\test>GetOS
Operating System Version: 7
Service Pack Major Version: 1
Architecture: 64-bit
F:\test>
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows command line related.
- Findstr - Search for strings - Windows CMD - SS64.com
- For /f- Loop through command output - Windows CMD - SS64.com
- If - Conditionally perform command - Windows CMD - SS64.com
- WMIC - Windows Management - Windows CMD - SS64.com
I can't believe this long and no ver command
C:\>ver
Microsoft Windows [Version 10.0.10586]
C:\>
It works in redirects so you can do
ver | find "Version 10."
But you should normally write "for this and all future versions" so you're better off enumerating through the previous ones.
systeminfo
gets many usefull infos like Operating system, System type (32/64 bit) and so long: