Computing.Net > Forums > General Hardware > checking for OS in a .bat file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

checking for OS in a .bat file

Reply to Message Icon

Name: T Deepthi
Date: May 19, 2009 at 00:33:30 Pacific
OS: Windows XP
Subcategory: General
Comment:

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"



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: May 19, 2009 at 01:28:53 Pacific
Reply:

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.


0

Response Number 2
Name: T Deepthi
Date: May 19, 2009 at 01:46:02 Pacific
Reply:

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.


0

Response Number 3
Name: Judago
Date: May 19, 2009 at 05:55:18 Pacific
Reply:

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

.........


0

Response Number 4
Name: T Deepthi
Date: May 19, 2009 at 21:53:18 Pacific
Reply:

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"


0

Response Number 5
Name: Judago
Date: May 20, 2009 at 00:45:29 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: T Deepthi
Date: May 20, 2009 at 01:51:44 Pacific
Reply:

Thank You...


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to General Hardware Forum Home


Sponsored links

Ads by Google


Results for: checking for OS in a .bat file

Convert string to lowercase in .bat file www.computing.net/answers/hardware/convert-string-to-lowercase-in-bat-file/57496.html

Laptop overheating? www.computing.net/answers/hardware/laptop-overheating/34848.html

2 os in a pc www.computing.net/answers/hardware/2-os-in-a-pc/58469.html