checking for OS in a .bat file

May 19, 2009 at 00:33:30
Specs: Windows XP
HI,
can any one tell me how to find the OS Host name in a .bat file ...
i have written a .bat file like this: but not working:

@echo off

set answerefilepath=%1

systeminfo | find "OS Name : Microsoft Windows XP"" > nul
if %ERRORLEVEL% == 0 goto ver_xp

echo Machine undetermined.
goto exit

:ver_xp
echo Xp is thw OS
goto exit

:exit
echo "exit"


See More: checking for OS in a .bat file

Report •


#1
May 19, 2009 at 01:28:53
You may want to have a look at the "ver" command, it is present on all versions of xp, while the home version doesn't have systeminfo.

Report •

#2
May 19, 2009 at 01:46:02
i have already tried taht...but i have some problem with "ver"....my requirement is that i have to find out what is the OS and then perfom MSMQ installation.....here i have with me 3 systems where in Vista is present and in some vista machine it's ver : 6.0.6000 and in some it's 6.0.6001.So ithought i cannot use ver command.That's the reason i needa command which tells me whetehr it's XP,Vista,2008 server or 2003 server.

Report •

#3
May 19, 2009 at 05:55:18
Ok, now I understand, anyway.

Your script basically works I just changed it a little:

@echo off
set answerefilepath=%1
2>nul systeminfo | >nul find "Microsoft Windows XP"&&goto ver_xp
echo Machine undetermined.
goto exit

:ver_xp
echo Xp is thw OS
goto exit

:exit
echo "exit"

You could speed things up a little but Just getting the
info you need straight from the registry:

@ECHO OFF
set product=
for /f "skip=4 tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "productname"') do (
if /i "%%b"=="mircosoft windows xp" goto ver_xp
....
....
)
echo Machine undetermined.
goto exit

.........


Report •

Related Solutions

#4
May 19, 2009 at 21:53:18
hi,
the below code is not working?
it's giving an error:
"FIle not found -GOTO
File not found - ver_xp"

@echo off
set answerefilepath=%1
2>nul systeminfo | >nul find "Microsoft Windows XP" goto ver_xp
echo Machine undetermined.
goto exit

:ver_xp
echo XP is the OS
goto exit

:exit
echo "exit"


Report •

#5
May 20, 2009 at 00:45:29
Where's the double ampersand before "goto ver xp"?? It basically means, if the return code for the program before the double ampersand is 0 execute the command after the double ampersand.

Without the ampersands find interprets "goto" and "ver_xp" as file names, responding that they cannot be found.

2>nul systeminfo | >nul find "Microsoft Windows XP" && goto ver_xp


Report •

#6
May 20, 2009 at 01:51:44
Thank You...

Report •


Ask Question