China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-13 06:38
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Question for the experts: can a batch file get Windows version information? View 1,513 Replies 8
Original Poster Posted 2004-01-16 00:00 ·  中国 广东 深圳 鹏博士宽带
初级用户
Credits 197
Posts 21
Joined 2004-01-09 00:00
22-year member
UID 15212
Gender Male
Status Offline
I often make various batch programs to use on different machines, and sometimes I need to perform different operations for different systems. So how can I use a batch file to get Windows version information (and make it general-purpose)?
In Windows I use the installer creation program CreatInstall 2000 to define macros and get values from the registry, and that works, but I don't know whether this can be done in a batch file.
Floor 2 Posted 2004-01-16 00:00 ·  加拿大 安大略省 多伦多
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Under DOS? Try the WINVER command.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 3 Posted 2004-01-18 00:00 ·  中国 广东 深圳 鹏博士宽带
初级用户
Credits 197
Posts 21
Joined 2004-01-09 00:00
22-year member
UID 15212
Gender Male
Status Offline
winver is a 32-bit program. It seems to exist only in Windows 98 (C:\WINDOWS\WINVER.EXE); I didn't find it in XP. So there goes the idea of general compatibility. More importantly, it only pops up a window and can't export the information for a batch file to use.
Floor 4 Posted 2004-01-18 00:00 ·  加拿大 安大略省 多伦多
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
zww3008: if you run WINVER under pure DOS, it won't pop up a window, but will display the Windows version number, for example: Windows 98
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 5 Posted 2004-01-26 00:00 ·  中国 山西 太原 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2004-02-03 00:00 ·  中国 广东 深圳 鹏博士宽带
初级用户
Credits 197
Posts 21
Joined 2004-01-09 00:00
22-year member
UID 15212
Gender Male
Status Offline
Heh~ just got back after the New Year!
What brother willsort introduced in post #5 are all ways to get DOS version information. What I need is a way to run a batch file in Windows and get WINDOWS version information such as windows 98/Me/2000/XP, etc. I wonder if there is any workable method?
Floor 7 Posted 2004-02-04 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re zww3008:

After actual testing, both under WIN 98 and WIN XP what I got was the WINDOWS version value, which is why I recommended it to you.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2004-02-04 00:00 ·  中国 广东 深圳 鹏博士宽带
初级用户
Credits 197
Posts 21
Joined 2004-01-09 00:00
22-year member
UID 15212
Gender Male
Status Offline
It really works, that's amazing! I often like to DIY little programs, and being able to obtain this kind of information is quite useful to me!
::getvar.bat
@if == prompt set %2=%3
@if == goto end
@echo off
%comspec% /c %0 invoke %1 %2>tt.bat
call tt

:end
But there are still some things I don't quite understand, please explain in detail:
1. What is prompt in the second line? Does it mean the %prompt% variable? If so, why isn't it enclosed in double % signs? And are it and the following set two commands written on one line? In win98 can two commands be written directly on one line? Where does %3 get its value from?
2. When using it, the command line is getvar curver $v. Do curver and $v correspond respectively to invoke and %1 in “%comspec% /c %0 invoke %1 %2”? Then what does %2 correspond to?
3. The question I'm asking you involves parameter issues with command /c and the like, which I've run into many times, but the help from command /? isn't very detailed, and I haven't found relevant materials either. Could you give a detailed and comprehensive introduction to the parameters of command?
Floor 9 Posted 2004-02-06 00:00 ·  中国 山西 太原 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re zww3008:

1. prompt is used here as an internal command, and set is merely its string-form parameter. After being output to tt, its content becomes set curver=current version, so set becomes an internal command and is called;

2. In Windows, two commands can be used on one line, but there are certain limitations, and it is not suitable for the needs here.
http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=12&ID=9106

3. The parameter correspondence is as follows:
::getvar.bat
This line is followed by execution of @if == prompt set %2=%3 here %1 is invoke, %2 is curver, and %3 is the system's current version
@if == goto end
@echo off
This line first executes %comspec% /c %0 invoke %1 %2>tt.bat here %1 is curver, %2 is $v, and invoke is the marker word for calling the subroutine
call tt

4. For detailed usage of command, you can refer to the DOS help document I uploaded. The link is as follows:
http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=12&ID=9266
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: