How do I determine if my system is Windows 10 using the command line?

32

5

I'm working with InstallAnywhere, an old program for creating installers. I would like to install a particular file, only in case of Windows XP and Windows Vista.

Due to InstallAnywhere limitations, this is not possible. I can only decide to delete the file once it has already been installed, based on a rule.

Within that rule, I can check for the platform on which I'm running, which gives me the possibility to check for Windows XP, Windows Vista, Windows 7, etc. but not for Windows 10. I can't say "Perform this action when the system is not XP or Vista", so I need to say "Perform this action on all those platforms, which are not XP or Vista".

However, I can launch command-line commands and catch the result, so here's my question: is there a command which I can use for determining if I'm working on a Windows 10 system?

Dominique

Posted 2016-05-12T09:08:19.043

Reputation: 1 013

Question was closed 2016-05-14T22:50:56.903

winver will pop up the About Windows dialog if typed in cmd or Start. Would that work? Alternatively - http://stackoverflow.com/questions/1792740/how-to-tell-what-version-of-windows-and-or-cmd-exe-a-batch-file-is-running-on – Tetsujin – 2016-05-12T09:17:54.480

Thanks for the reply, but I'm looking for a command-line command which gives an answer in the command-line, I can't use the information in a batch-type way when a messagebox pops up. – Dominique – 2016-05-12T11:14:32.727

Check for cmd.exe version, it's the easiest and supported at least since XP. There is a question about it. – KeyWeeUsr – 2016-05-12T11:55:40.883

I've just tried it on my Windows 7 system: cmd --version give as a result Microsoft Windows [Version 6.1.7601], so the relation between cmd version and Windows version seems not that straightforward, what can I expect on Windows 10? – Dominique – 2016-05-12T12:03:19.273

2

google cmd versions, each os has different version number, you can check for that and you don't need any unnecessary long script or another program - here

– KeyWeeUsr – 2016-05-12T13:38:27.800

You're right, KeyWeeUsr, on the URL "http://www.windows-commandline.com/find-windows-os-version-from-command/" I've found some interesting information.

– Dominique – 2016-05-12T14:22:47.633

5

Just type ver. For example, on my Windows 7 system I get "Microsoft Windows [Version 6.1.7601]" which tells me that I am running Windows 7 (which has version number 6.1).

– Andreas Rejbrand – 2016-05-12T16:30:27.327

Answers

54

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 or 10.

Example output:

F:\test>GetOS
Operating System Version: 7
Service Pack Major Version: 1
Architecture: 64-bit

F:\test>

Further Reading

DavidPostill

Posted 2016-05-12T09:08:19.043

Reputation: 118 938

2After some testing, I have decided to use the following command: wmic os get Caption | findstr /V Caption – Dominique – 2016-05-12T11:06:00.013

@DavidPostill I have tested the batch file. I think it needs a pause before the endlocal to give the user a chance to read the output before the window closes. Does that follow for you too? – Matthew – 2016-05-12T13:10:26.543

1@Matthew I think the expectation is that some other system would be running the batch file and capturing its output (or it would be called manually from an existing Command prompt window). – TripeHound – 2016-05-12T13:23:13.760

@mathew pause is not necessary running from cmd prompt. Answer is to show technique rather than fit all scenarios. – DavidPostill – 2016-05-12T13:26:41.097

Ok, I obviously misunderstood the answer. My limited experience with batch led me to copy the file above to a notepad and save it as "GetOS.cmd", which seemed to be the implication of the post. But running this cmd file does not display the output. – Matthew – 2016-05-12T13:32:55.797

1@mathew open a cmd prompt where you saved the file and type getos – DavidPostill – 2016-05-12T13:35:25.010

35

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.

Joshua

Posted 2016-05-12T09:08:19.043

Reputation: 619

FYI ver does not work in PowerShell. It is CMD specific. – Keltari – 2016-05-12T22:18:10.353

3@Keltari But iex "ver" does! – Ben N – 2016-05-13T01:10:29.957

The output of ver can be a bit misleading. On the machine I am sitting at right now it returns Microsoft Windows [Version 6.1.7601]. But i am quite certain it runs Windows 7, not Windows 6. – Philipp – 2016-05-13T13:13:42.920

@Philipp Yes, Windows 7 and 8 are "really" patch releases of Vista, 6.1 and 6.2 respectively; the major version bump is strictly marketing. I do not know whether the changes in Windows 10 are significant enough to warrant a major version bump. (From the hardline software engineering perspective, the major version of any software should only ever be bumped to indicate a backward compatibility break; it follows that large major versions are bad. Unfortunately, the marketing department likes large numbers.) – zwol – 2016-05-13T13:37:09.263

1

@Philipp - its easy to find a map from version number to marketing names, e.g., here

– davidbak – 2016-05-13T16:46:41.523

Windows 7 and 8/8.1 used 6.1/6.2/6.3 because vista had such a significantly changed driver architecture from XP that they coded it to only work if the system reported Windows major version as 6. In Windows 10 microsoft felt that drivers have advanced far enough since then to change the number again. The biggest offenders if I recall were graphics vendors. I wouldn't call them "patches" of vista, even though they closely follow its driver model. – Mgamerz – 2016-05-13T19:17:55.233

Nice to know about this command. It's unclear what you mean in the first line, though. – Marc.2377 – 2016-05-13T21:38:35.010

The question was 7 hours old and the answer should be stupid obvious to anybody whose been around awhile. – Joshua – 2016-05-13T21:52:08.010

In fact the numbering is the "NT" version, not strictly the Windows version. – mckenzm – 2016-05-14T09:42:48.000

18

systeminfo

gets many usefull infos like Operating system, System type (32/64 bit) and so long:

enter image description here

duDE

Posted 2016-05-12T09:08:19.043

Reputation: 14 097

Yes, I would recommend systeminfo also. As you can see from the image above, it will display your operating system as well as other information you may need. – Matthew – 2016-05-12T10:00:02.583

3Thanks for the quick reply. systeminfo indeed gives the information I'm looking for (hence the upvote), but it takes quite some time (on my PC it takes more than 15 seconds). Therefore I've opted for the wmic solution, found in the next answer. – Dominique – 2016-05-12T11:08:17.493

1This is what I ask people to run when I need to find out os/version they are running on: cmd /c systeminfo | findstr /B /C:"OS Name" /C:"OS Version" – Andrew Savinykh – 2016-05-12T22:56:13.177

1systeminfo's output is language dependent, so quite useless if you want ot run it on a larger scale – Stephan – 2016-05-14T18:03:50.353

1

I don't have any experience with InstallAnywhere but there are two options to see what OS is installed using a command-line.

  1. Using Cmd

    systeminfo.exe
    

    Using the command systeminfo.exe, you can see result of under the field OS Name. This may give you more information than you require.

    More information on this command can be found in Microsoft TechNet.

  2. Powershell

    Alternatively you could use the following Powershell script which will return the exact information you want.

    Get-CimInstance Win32_OperatingSystem | Select-Object  Caption | ForEach{ $_.Caption }
    

Tim Mahood

Posted 2016-05-12T09:08:19.043

Reputation: 84