Craig <(E-Mail Removed)> wrote:
> I have a simple batch file that I've written that doesn't properly detect
> which OS I'm running, and I'm not sure why. Here it is:
>
> @echo off
> echo.
> for /F "tokens=2* delims= " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\
> SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName') do set
> os=%%B
>
> echo %os%
> pause
>
> If "%OS%" == Microsoft Windows XP
> goto xp
>
> If "%OS%" == Microsoft Windows 2000
> goto w2k
>
> goto exit
>
> :w2k
> echo You're running Windows 2000
> pause
> exit
>
> :xp
> echo You're running Windows XP
> pause
>
> :exit
> exit
>
> What am I doing wrong??? Also, if this batch file is run on another OS
> (Win98, etc.), it should just exit, right???
Hi Craig,
Isn't this the same thing you asked a couple of weeks ago?
In any case, the answer to your question is "no." It won't "just exit." It
will fail with a syntax error on Win9x because Win9x command.com's FOR
command does not have a /F switch.
A better alternative to all of this is to use my OSVER.EXE, which works on
Win9x. On NT and later, it can also tell you which service pack, and
whether the machine is a server, DC, or workstation.
http://home.comcast.net/~stewartb/wast.html
Bill