View unanswered posts | View active topics It is currently 22 Jul 2014 07:23



Post new topic Reply to topic  [ 5 posts ] 
Find OS 
Author Message

Joined: 08 Mar 2013 18:02
Posts: 6
Location: Dinnington, Newcastle upon Tyne, UK
Post Find OS
Evening all,

I'm very new to writing batch files and need a bit of help. I've "borrowed" some code off the internet to find the OS and now I want to add a "goto" command in but I can't seem to get it to work. Where am I going wrong?

Original code:

Code:
::Identify OS
ver | find /i "version 6.2." > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows 8
ver | find /i "version 6.1." > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows 7
ver | find /i "version 6.0." > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows Vista
ver | find /i "version 5.1." > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows XP
ver | find /i "version 5.2." > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows 2003
ver | find /i "Windows 2000" > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows 2000
ver | find /i "Windows NT" > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows NT
ver | find /i ">Windows ME" > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows ME
ver | find /i "Windows 98" > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows 98
ver | find /i "Windows 95" > nul
if %errorlevel%==0 set $VERSIONWINDOWS=Windows 95

::Identify bit
IF NOT EXIST "%SYSTEMDRIVE%\Program Files (x86)" set $VERSIONBIT=32 bit
IF EXIST "%SYSTEMDRIVE%\Program Files (x86)" set $VERSIONBIT=64 bit

::Display result
echo %$VERSIONWINDOWS% %$VERSIONBIT%
echo.
pause


I'm now trying to add in, after "pause", the "goto command of:

Code:
if %$VERSIONWINDOWS%==Windows 7 goto :ver_7

:ver_8
echo Windows 8

:ver_7
echo Windows 7


I'm sure it's simple but I have no idea what's wrong. I've tried every version of the goto command I can think of!


11 Mar 2013 17:19
Profile ICQ WWW

Joined: 23 Dec 2011 13:59
Posts: 1751
Post Re: Find OS
Put double quotes around the values you are comparing.


11 Mar 2013 17:50
Profile

Joined: 08 Mar 2013 18:02
Posts: 6
Location: Dinnington, Newcastle upon Tyne, UK
Post Re: Find OS
Squashman wrote:
Put double quotes around the values you are comparing.

Like a charm, thanks!!


11 Mar 2013 18:11
Profile ICQ WWW
Expert

Joined: 06 Dec 2011 22:15
Posts: 704
Location: México City, México
Post Re: Find OS
I like it! :D

Code:
@echo off
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) 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%
echo/
pause


::Goto right version
goto %Version: =_%


:Windows_8
echo Windows 8

:Windows_7
echo Windows 7

Antonio


11 Mar 2013 21:10
Profile

Joined: 24 Dec 2010 12:16
Posts: 79
Location: Micanopy Florida
Post Re: Find OS
@Antonio
I like it as well! Two quick tries with your script on two OS's I get:

Windows XP 32 bit
Windows 7 64 bit

Nice work!


11 Mar 2013 23:00
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.