30

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?

7
  • winver will pop up the About Windows dialog if typed in cmd or Start. Would that work? Alternatively - stackoverflow.com/questions/1792740/…
    – Tetsujin
    May 12, 2016 at 9:17
  • 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
    May 12, 2016 at 11:14
  • Check for cmd.exe version, it's the easiest and supported at least since XP. There is a question about it.
    – KeyWeeUsr
    May 12, 2016 at 11:55
  • 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
    May 12, 2016 at 13:38
  • 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). May 12, 2016 at 16:30

4 Answers 4

53

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

0
34

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.

9
  • FYI ver does not work in PowerShell. It is CMD specific.
    – Keltari
    May 12, 2016 at 22:18
  • 3
    @Keltari But iex "ver" does!
    – Ben N
    May 13, 2016 at 1:10
  • 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
    May 13, 2016 at 13:13
  • @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
    May 13, 2016 at 13:37
  • 1
    @Philipp - its easy to find a map from version number to marketing names, e.g., here
    – davidbak
    May 13, 2016 at 16:46
18

systeminfo

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

enter image description here

4
  • 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
    May 12, 2016 at 10:00
  • 3
    Thanks 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
    May 12, 2016 at 11:08
  • 1
    This 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" May 12, 2016 at 22:56
  • 1
    systeminfo's output is language dependent, so quite useless if you want ot run it on a larger scale
    – Stephan
    May 14, 2016 at 18:03
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 }
    

Not the answer you're looking for? Browse other questions tagged .