0

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

1 Answers1

0

Try like this :

if /I "%Version% %Type%"="windows 8.1 64 bit" goto:ver_8_x64
SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • I put if /I "%Version% %Type%"="Windows 8.1 64 bit" goto ver_8.1_x64 it didn't work i put yours as well it didn't work either. – Chad Ballard Jul 23 '14 at 00:45
  • I tested it and it work fine on my windows 7 32 bit. – SachaDee Jul 23 '14 at 01:08
  • hey could you email me your file that's working? ccallie2001@yahoo.com for some reason mine is not working and im using the same code lol – Chad Ballard Jul 23 '14 at 04:55
  • Well or you could post your full code that is in the file that is working?! in the comments here? -sachadee – Chad Ballard Jul 24 '14 at 00:53
  • Okay thanks for sending it to my email. I took a look and found out what was up. You posted this in your first comment above if /I "%Version% %Type%"="windows 8.1 64 bit" goto:ver_8_x64 but in your file it was like this if "%Version% %type%"=="Windows 7 32 bit" goto ver7 so i put this if /I "%Version% %type%"=="Windows 7 32 bit" goto ver7. It works now thanks! – Chad Ballard Jul 24 '14 at 02:43
  • I also add a line like the one in the last comment for each vers and type so if it wasn't a match it goes to the next line. I also made the changes to the code in the question so its correct and works could you double check it for me by copying it and making a batch and testing it sachadee. Also thanks again. – Chad Ballard Jul 24 '14 at 03:01