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-01 02:20
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » How to write a program under DOS to detect whether a CD-ROM drive is installed? View 7,321 Replies 45
Original Poster Posted 2003-01-29 00:00 ·  中国 广西 百色 电信
初级用户
Credits 119
Posts 7
Joined 2002-12-05 00:00
23-year member
UID 419
Gender Male
Status Offline
How can I write a C or assembly program under DOS to determine whether a CD-ROM drive is installed?
Could some expert please give me some pointers, maybe show a code snippet.
Thanks!!!
Floor 2 Posted 2003-01-29 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Good idea.
Wengier - 新DOS时代

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

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

Floor 3 Posted 2003-01-30 00:00 ·  中国 浙江 衢州 电信
中级用户
Credits 210
Posts 39
Joined 2002-12-30 00:00
23-year member
UID 638
Gender Male
Status Offline
It's extremely simple, even BASIC can do it. The principle is just to determine whether Mscdex.exe is already running.
Floor 4 Posted 2003-01-30 00:00 ·  中国 北京 263网络通信股份有限公司
银牌会员
★★★
nre
Credits 1,210
Posts 361
Joined 2002-12-28 00:00
23-year member
UID 629
Gender Male
Status Offline
The following is a quote from qzxym on 2003-1-30 22:40:16:
It's extremely simple, even BASIC can do it. The principle is just to determine whether Mscdex.exe is already running.

What's the point of saying that? How exactly do you do it?

Teamwork !
Floor 5 Posted 2003-01-30 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Just checking whether MSCDEX is loaded is useless, and there are also other CD-ROM extension drivers, such as SHSUCD and so on.
Wengier - 新DOS时代

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

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

Floor 6 Posted 2003-01-31 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
I just adapted the source code of that FINDRAMD mentioned earlier by baobolz and turned it into a FINDCD program. It can locate the drive letter where the CD is and set it to the environment variable CDROM. It has two obvious advantages:

1: It fully supports CLOAKING+MSCDEX, while the FINDCD.COM 1.02 on the Internet does not;
2: It can directly set the CD drive letter to the variable CDROM, which is very convenient to use, and there is no need to check any ERRORLEVEL value.

I have uploaded it to the forum, download link:
Open attachment link expired (admin note 2009-4-28)

Wengier - 新DOS时代

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

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

Floor 7 Posted 2003-02-06 00:00 ·  中国 广东 佛山 禅城区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
Very good, very good. This makes creating boot disks much more convenient.
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
Floor 8 Posted 2003-02-06 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
I made some more enhancements to FINDCD and uploaded it again:

Open attachment link expired (admin note 2009-4-28)

Note: it also fixes the BUG where the system would hang when there was no CD-ROM drive.


Wengier - 新DOS时代

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

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

Floor 9 Posted 2003-02-07 00:00 ·  中国 北京 263网络通信股份有限公司
银牌会员
★★★
nre
Credits 1,210
Posts 361
Joined 2002-12-28 00:00
23-year member
UID 629
Gender Male
Status Offline
Upload the original source code too. It would help everyone improve their skills.

Teamwork !
Floor 10 Posted 2003-02-07 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
All right, below is part of the source code of this program:

Program initialization section (PASCAL source code):

program findcd;
const
env: arrayof Char='CDROM=c:'; <- prepares the environment variable
var
drvs: array of Char; <- CD-ROM character list
envp: PChar;

CD-ROM search subroutine (assembly source code):

procedure setdrv; assembler;
asm mov bx,0
mov ax,1500h
int 2fh <- calls interrupt to obtain CD-ROM status
cmp bx,1 <- checks whether the CD-ROM drive is installed
jc @@m <- if not, exit subroutine
push bx
push ds
pop es
mov bx,offset drvs
mov ax,150Dh
int 2Fh
pop cx
@@l: add byte ptr ,'A'
inc bx
loop @@l
mov byte ptr ,0
@@m:
end;

Add environment variable subroutine (assembly source code, omitted);

Main calling program (PASCAL source code):
begin
setdrv; <- calls the CD-ROM search subroutine;
if ord(drvs)=0 then <- if there is no CD-ROM drive, display “No CD-ROM found”;
WriteLn('No CD-ROM found.'
else begin
env:=drvs; <- if a CD-ROM drive exists, add the first CD-ROM drive letter to the environment variable CDROM;
WriteLn(env); <- display “CDROM=x:” on the screen;
if not InsertEnvVar <- calls the add environment variable subroutine;
then WriteLn('Cannot set environment variable!'; <- if it cannot be added, display an error;
exit;
end;
end. <- program ends.
Wengier - 新DOS时代

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

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

Floor 11 Posted 2003-02-07 00:00 ·  中国 广东 汕头 电信
银牌会员
★★★
Credits 1,451
Posts 446
Joined 2002-10-20 00:00
23-year member
UID 29
Gender Male
Status Offline
Does it support dual CD-ROM drives and triple CD-ROM drives?
Floor 12 Posted 2003-02-08 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
pfox: Good idea, so I just enhanced FINDCD again. Download it here:
Open attachment link expired (admin note 2009-4-28)

The feature of this version is that “FINDCD n” (n is a number) will set the CDROM environment variable to the nth CD-ROM drive. If n is not specified, it defaults to the first CD-ROM drive (that is, n=1). If n is 0 or not a number, then CDROM will be set to the number of CD-ROM drives.

Suppose there are three CD-ROM drives E:、F:、G:, then running “FINDCD” or “FINDCD 1” will give “CDROM=E:”, and running “FINDCD 3” will give “CDROM=G:”; if you run “FINDCD 0” you will get “CDROM=3” (that is, there are three CD-ROM drives); if you run “FINDCD 4” it will say CD-ROM drive not found (because there are only three CD-ROM drives).


Wengier - 新DOS时代

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

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

Floor 13 Posted 2003-02-08 00:00 ·  中国 广东 汕头 电信
银牌会员
★★★
Credits 1,451
Posts 446
Joined 2002-10-20 00:00
23-year member
UID 29
Gender Male
Status Offline
Good!

Wengier, could you enhance it a bit more? When running FindCD without parameters,
have it directly assign the drive letter of the first CDROM to the CDROM environment variable, and if there is a
second or third CDROM drive letter, assign them directly to CDROM1 and CDROM2?
That way, in a boot disk, cda.exe can be used directly to determine whether there
is a disc in the CD-ROM drive and whether a file exists on it,
and if so it can be executed or called directly.






Floor 14 Posted 2003-02-15 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Why not write a batch file to do it? Since after running FINDCD 0 the value of %CDROM% is the number of CD-ROM drives, you can make a batch loop and, based on the number of CD-ROM drives, set all the CD-ROM drive letters into the %CDROM% variables.
Wengier - 新DOS时代

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

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

Floor 15 Posted 2003-02-15 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
I just wrote a simple DOS batch file. Using the FINDCD program above, it can conveniently set CDROM1, CDROM2, etc. in sequence to the CD-ROM drive letters. The program is as follows:
@echo off
set n=0
:loop
set cdrom=
findcd %n% (that is: call the FINDCD above)
if %n%==0 set cdn=%cdrom%
if not %n%==0 set cdrom%n%=%cdrom%
if %n%#==%cdn%# goto end
count n (that is: n=n+1)
goto loop
:end
set n=
set cdn=
set cdrom=
echo.
Wengier - 新DOS时代

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

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

Forum Jump: