31

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?

Burgi
  • 6,768
Dominique
  • 2,373

4 Answers4

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
  • 162,382
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.

Joshua
  • 843
18

systeminfo

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

enter image description here

Leo Chapiro
  • 15,705
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 }
    
muru
  • 1,336
Tim Mahood
  • 114
  • 1
  • 5