Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CD ROM presence test

Status
Not open for further replies.

JamesBee

Programmer
Aug 8, 2000
3
GB
I'm developing some computer based training material and I need to write some code that will test for the presence of a CD ROM in the CD drive (the drive will always be D:). At the moment I'm using the following :<br><br>&lt;head&gt;<br>&lt;script language=&quot;JavaScript&quot;&gt;<br>&lt;!--#<br>function noCD()<br>{<br>alert(&quot;Please put assets CD into your CD-ROM drive.&quot;);<br>}<br>//--&gt;<br>&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;img src=&quot;d:\\image\\testimage.gif&quot; width=&quot;1&quot; height=&quot;1&quot; border=&quot;0&quot; valign=&quot;middle&quot; onerror=&quot;noCD()&quot;&gt;<br>&lt;/body&gt;<br><br>This works, but only on a fast PC. It won't work on old P166's for instance. Anyone know a better way to test for the presence of a CD ROM? <br>
 
As soon as some people read this, I know the spit will hit the fan.&nbsp;&nbsp;There's a series of code in Microsoft JScript and VBScript, FileSystemObject that will give you access to files and drives on the visitors computer.&nbsp;&nbsp;They must grant access or lower the security on their system, but once your in, you can test for drives, folders, and files.<br><br>Here's an example:<br><br>function ShowDriveInfo1(drvPath)<br>{<br>&nbsp;&nbsp;&nbsp;var fso, drv, s =&quot;&quot;;<br>&nbsp;&nbsp;&nbsp;fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);<br>&nbsp;&nbsp;&nbsp;drv = fso.GetDrive(fso.GetDriveName(drvPath));<br>&nbsp;&nbsp;&nbsp;s += &quot;Drive &quot; + drvPath.toUpperCase()+ &quot; - &quot;;<br>&nbsp;&nbsp;&nbsp;s += drv.VolumeName + &quot;&lt;br&gt;&quot;;<br>&nbsp;&nbsp;&nbsp;s += &quot;Total Space: &quot; + drv.TotalSize / 1024;<br>&nbsp;&nbsp;&nbsp;s += &quot; Kb&quot; + &quot;&lt;br&gt;&quot;; <br>&nbsp;&nbsp;&nbsp;s += &quot;Free Space: &quot; + drv.FreeSpace / 1024;<br>&nbsp;&nbsp;&nbsp;s += &quot; Kb&quot; + &quot;&lt;br&gt;&quot;;<br>&nbsp;&nbsp;&nbsp;Response.Write(s);<br>}<br><br>This script will display the free space and total size of a drive.<br><br>More information about FSO can be found at <A HREF=" TARGET="_new">
 
Even if you did check to see if the cd-rom was present, you would have to dynamically create the path to the cd-rom to display the image.&nbsp;&nbsp;Not all cd-rom drives are labeled as the 'D:' drive.
 
Thankyou for the response. As my client is a high street bank I don't think they'll be too open to lowering security in there browsers. I'll look into it though, there might be a solution along those lines.<br><br>JamesB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top