how can I determine in a Batch-Scipt which OS is running? What technics do you use and prefer? Win 2000 or OS prior to Win 2000, Win XP or Win Vista and Win7
On Mar 6, 2:43 pm, "Thomas Steinbach" <steinb...@gmx-topmail.de> wrote:
> Hello NG,
> how can I determine in a Batch-Scipt which OS > is running? What technics do you use and prefer? > Win 2000 or OS prior to Win 2000, Win XP > or Win Vista and Win7
> Thomas
A common way is to parse/match the output of the VER statement.
> how can I determine in a Batch-Scipt which OS > is running? What technics do you use and prefer? > Win 2000 or OS prior to Win 2000, Win XP > or Win Vista and Win7
> how can I determine in a Batch-Scipt which OS > is running? What technics do you use and prefer? > Win 2000 or OS prior to Win 2000, Win XP > or Win Vista and Win7
Sorry, I missed the original question but this batch file I found a few months ago might help you...
@ECHO OFF
:: Win9x checks ::::::::::::
VER |find /i "Windows 95" >NUL IF NOT ERRORLEVEL 1 GOTO W9598ME
VER |find /i "Windows 98" >NUL IF NOT ERRORLEVEL 1 GOTO W9598ME
VER |find /i "Windows Millennium" >NUL IF NOT ERRORLEVEL 1 GOTO W9598ME
:: NT/XP checks :::::::::::: VER | find "XP" > nul IF %errorlevel% EQU 0 GOTO s_win_XP
VER | find "2000" > nul IF %errorlevel% EQU 0 GOTO s_win_2000
VER | find "NT" > nul IF %errorlevel% EQU 0 GOTO s_win_NT
I was wrong, indeed: -version parameter is not valid, therefore, cmd ignores it and just starts a new nested interpreter.
As compensation, devise a new way to determine the version, and the result is the most full.
For example, command 'ver' gets: Microsoft Windows XP and this code gets: Microsoft Windows XP Professional
If not the first method uses the second command is command 'ver'.
:::::::::::::::::::::::::::::::::::::::::::::::::::::Code:::::::::::::::::: :::::::::::::::::::::::::::::::: @echo off
for /f "tokens=* usebackq eol=" %%o in ("%windir%\system32\eula.txt") do ^ set "_os__version_=%%o" & goto :continue: :continue: if defined _os__version_ (echo.%_os__version_:®=%) else ^ for /f "tokens=1 delims=[ eol=" %%o in ('ver') do echo.%%o
for /f "tokens=* eol=" %%o in (%windir%\system32\eula.txt) do ( set "_os__version_=%%o" & goto :continue: ) :continue: if defined _os__version_ (echo.%_os__version_:®=%) else ( for /f "tokens=1 delims=[ eol=" %%o in ('ver') do echo.%%o )
0x0...@gmail.com wrote: > @echo off > for /f "tokens=* usebackq eol=" %%o in ("%windir%\system32\eula.txt") > do ^
(etc)
I am sorry to shoot your effort down, but it makes bad logical sense, since your code is heavily version dependent. It is one task that should be done with as version independent code as ever possible.
> 0x0...@gmail.com wrote: > > @echo off > > for /f "tokens=* usebackq eol=" %%o in ("%windir%\system32\eula.txt") > > do ^
> (etc)
> I am sorry to shoot your effort down, but it makes bad logical sense, > since your code is heavily version dependent. It is one task that should > be done with as version independent code as ever possible.
first, it bothers me to quote from the wrong code, when it could have quoted the correct code I published 10 minutes later (and the answer is two hours later).
Try it on Windows NT, 2000, XP and Vista, and I will see which version is so dependent.
Not always be thinking about compatibility programmed, for example, I do not care to run this code on Windows 98 or DOS, why not just use my batch in these systems, for example, the command else does not exist in Windows 98.
My version, delivers more complete, that all that you put in your faq.
He devised a new way to know if the operating system is NT or 9x family.
::::::::::::::::::::Code::::::::::::::::::::::: set _osfamily=nt ver /r 2>nul if not errorlevel 1 set _osfamily=9x echo osfamily:%_osfamily% ::::::::::::::::::::Code:::::::::::::::::::::::
ver /r is undocumented in windows 9x family. This not exist in windows nt family. ver /r 2>nul set errorlevel to 1 in nt family, but unset in windows 9x family.
0x0...@gmail.com wrote: > Timo Salmi wrote: >> 0x0...@gmail.com wrote: >>> @echo off >>> for /f "tokens=* usebackq eol=" %%o in >>> ("%windir%\system32\eula.txt") do ^
>> (etc)
>> I am sorry to shoot your effort down, but it makes bad logical sense, >> since your code is heavily version dependent. It is one task that >> should be done with as version independent code as ever possible.
> first, it bothers me to quote from the wrong code, when it could have > quoted the correct code I published 10 minutes later (and the answer > is two hours later).
You apperantly don't understand newsgroup posting.
> Try it on Windows NT, 2000, XP and Vista, and I will see which version > is so dependent.
No, YOU do your own testing prior to publishing.
> Not always be thinking about compatibility programmed, for example, I > do not care to run this code on Windows 98 or DOS, why not just use my > batch in these systems, for example, the command else does not exist > in Windows 98.
> My version, delivers more complete, that all that you put in your faq.
Your later versions were also version dependent as well as questionable. Reading eula.txt for OS version is a haphazard approach. While you may not care about Windows 98 or DOS systems, there are others reading this discussion who may.
-- Todd Vargo (Post questions to group only. Remove "z" to email personal messages)
> 0x0...@gmail.com wrote: > > Timo Salmi wrote: > >> 0x0...@gmail.com wrote: > >>> @echo off > >>> for /f "tokens=* usebackq eol=" %%o in > >>> ("%windir%\system32\eula.txt") do ^
> >> (etc)
> >> I am sorry to shoot your effort down, but it makes bad logical sense, > >> since your code is heavily version dependent. It is one task that > >> should be done with as version independent code as ever possible.
> > first, it bothers me to quote from the wrong code, when it could have > > quoted the correct code I published 10 minutes later (and the answer > > is two hours later).
> You apperantly don't understand newsgroup posting.
> > Try it on Windows NT, 2000, XP and Vista, and I will see which version > > is so dependent.
> No, YOU do your own testing prior to publishing.
> > Not always be thinking about compatibility programmed, for example, I > > do not care to run this code on Windows 98 or DOS, why not just use my > > batch in these systems, for example, the command else does not exist > > in Windows 98.
> > My version, delivers more complete, that all that you put in your faq.
> Your later versions were also version dependent as well as questionable. > Reading eula.txt for OS version is a haphazard approach. While you may not > care about Windows 98 or DOS systems, there are others reading this > discussion who may.
> -- > Todd Vargo > (Post questions to group only. Remove "z" to email personal messages)
At least I do, how many times I found the operating system has to differentiate between Windows NT and 2000 or XP, for example because the command output Reg.exe query is different but if you are looking for a script compatible with command.com Windows 98 SE lose all of the NT, eg nesting of commands, set /p, for /f, else, & && || etc.
The code that reads eula.txt rioja tested on Windows 2000 and XP, although a user has already said that it does not work in Vista. In Windows 98 the file is called LICENSE.TXT but can not be parsed with a for /f
The universal detector Timo said: Unknow in my Windows XP.
On Sun, 08 Mar 2009 08:58:58 -0000, Timo Salmi <t...@uwasa.fi> wrote: > 0x0...@gmail.com wrote: >> I will make a universal windows dos detector version, give me a three >> days please.
> Not that new or revisited solutions wouldn't always be welcome.
> All the best, Timo
Well there's the internal "DOS" version available via int 21 functions, as long as you're on an intel platform. I felt somone in this group (or AMB) had made some ascii assembler code about 5 years ago, but I can't find it now.(later) Oh, seems I did keep it.
We tested on Windows 98, 2000, 2003, XP and tried the syntax in MS DOS 7.10, also tried it using cmd.exe from Windows NT 4 server. I have not tested on Vista, but I think it should work.
The version of the Timo is limited by language, "software version" is in my windows "versión del programa", because it did not work, so I decided to make an improvement for the family nt can be executed in any language.
> Here is my improve version of Timo Salmi detector: > I have not tested on Vista, but I think it should work.
In Windows Vista SP 1 it prints:
Operating System: Windows Vista or Seven
But If you get to that point you can run VER and see that it is not version seven. My Windows Vista SP1 prints "Microsoft Windows [Version 6.0.6001]", but I have access to only this one computer so I don't know if the service pack is encoded in the version number.
also can view the updated script (beta 3), and download iso image (52 KB) with os.bat for testing in operating systems with virtual machine. I test in MS-DOS 7.10 and Windows 95, and works.