windowsbatch-fileoperating-systemgo-to-definition

How to fix the goto portion of the file to take the version and type of OS


This scripts question has been answer with the help of user: sachadee. So special thanks goes to him so all you have to do is copy and paste into notepad or other text editor and save as .bat file and add your code in the different sections.

@echo
setlocal EnableDelayedExpansion

::Identify OS
for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8 6.3.=8.1) do (
if "!Version!" equ "this" (
  set Version=Windows %%a
  ) else if "!ver: %%a=!" neq "%ver%" (
  set Version=this
 )
)

::Identify bit
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
set Type=64 bit
) else (
set Type=32 bit
)

::Display result
echo %Version% %Type%

:: This code matches it to the correct section below based on what version and type
:: of OS your running

if /I "%Version% %Type%"=="Windows 2000" ( goto :ver_2000 )

if /I "%Version% %Type%"=="Windows XP 32 bit" ( goto :ver_XP )

if /I "%Version% %Type%"=="Windows XP 64 bit" ( goto :ver_XP_x64 )

if /I "%Version% %Type%"=="Windows Vista 32 bit" ( goto :ver_Vista )

if /I "%Version% %Type%"=="Windows Vista 64 bit" ( goto :ver_Vista_x64 )

if /I "%Version% %Type%"=="Windows 7 32 bit" ( goto :ver_7 )

if /I "%Version% %Type%"=="Windows 7 64 bit" ( goto :ver_7_x64 )

if /I "%Version% %Type%"=="Windows 8 32 bit" ( goto :ver_8 )

if /I "%Version% %Type%"=="Windows 8 64 bit" ( goto :ver_8_x64 )

if /I "%Version% %Type%"=="Windows 8.1 32 bit" ( goto :ver_8.1 )

if /I "%Version% %Type%"=="Windows 8.1 64 bit" ( goto :ver_8.1_x64 )


:: runs program or script depending on windows version ::

:ver_2000
:Run Windows 2000 specific commands here.
echo Windows 2000
pause
your code goes here
goto exit

:ver_XP
:Run Windows XP specific commands here.
echo Windows XP 32bit
pause
your code goes here
goto exit

:ver_XP_x64
:Run Windows XP 64bit specific commands here.
echo Windows XP 64bit
pause
your code goes here
goto exit

:ver_Vista
:Run Windows Vista specific commands here.
echo Windows Vista 32bit
pause
your code goes here
goto exit

:ver_Vista_x64
:Run Windows Vista 64bit specific commands here.
echo Windows Vista 64bit
pause
your code goes here
goto exit

:ver_7
:Run Windows 7 specific commands here.
echo Windows 7 32bit
pause
your code goes here
goto exit

:ver_7_x64
:Run Windows 7 64bit specific commands here.
echo Windows 7 64bit
pause
your code goes here
goto exit

:ver_2008
:Run Windows Server 2008 specific commands here.
echo Windows Server 2008 32bit
pause
your code goes here
goto exit

:ver_2008_x64
:Run Windows Server 2008 64bit specific commands here.
echo Windows Server 2008 64bit
pause
your code goes here
goto exit

:ver_8
:Run Windows 8 specific commands here.
echo Windows 8 32bit
pause
your code goes here
goto exit

:ver_8_x64
:Run Windows 8 64bit specific commands here.
echo Windows 8 64bit
pause
your code goes here
goto exit

:ver_8.1
:Run Windows 8 specific commands here.
echo Windows 8.1 32bit
pause
your code goes here
goto exit

:ver_8.1_x64
:Run Windows 8.1 64bit specific commands here.
echo Windows 8.1 64bit
pause
your code goes here
goto exit

:exit

Solution

  • Try like this :

    if /I "%Version% %Type%"="windows 8.1 64 bit" goto:ver_8_x64