473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

CD ROM Detection

Ali Rizwan
925 512MB
Hi all,
I have write this program which is used to detect CD ROM.
You just need to add a command button.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
  4.     (ByVal nDrive As String) As Long
  5.  
  6. Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
  7.     Alias "GetLogicalDriveStringsA" _
  8.     (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  9.  
  10. Const DRIVE_CDROM& = 5
  11.  
  12. Public Function GetDriveStrings() As String
  13.     ' Wrapper for calling the GetLogicalDriveStrings api
  14.  
  15.     Dim result As Long          ' Result of our API calls
  16.     Dim strDrives As String     ' String to pass to API call
  17.     Dim lenStrDrives As Long    ' Length of the above string
  18.  
  19.     ' Call GetLogicalDriveStrings with a buffer size of zero to
  20.     ' find out how large our stringbuffer needs to be
  21.     result = GetLogicalDriveStrings(0, strDrives)
  22.  
  23.     strDrives = String(result, 0)
  24.     lenStrDrives = result
  25.  
  26.     ' Call again with our new buffer
  27.     result = GetLogicalDriveStrings(lenStrDrives, strDrives)
  28.  
  29.     If result = 0 Then
  30.         ' There was some error calling the API
  31.         ' Pass back an empty string
  32.         ' NOTE - TODO: Implement proper error handling here
  33.         GetDriveStrings = ""
  34.     Else
  35.         GetDriveStrings = strDrives
  36.     End If
  37. End Function
  38.  
  39. Private Sub Command1_Click()
  40.     Dim strDrives As String
  41.  
  42.     ' Find out what drives we have on this machine
  43.     strDrives = GetDriveStrings()
  44.  
  45.     If strDrives = "" Then
  46.         ' No drives were found
  47.         MsgBox "No Drives were found!", vbCritical
  48.     Else
  49.         ' Walk through the string and check the type of each drive
  50.         ' displaying any cd-rom drives we find
  51.         Dim pos As Long
  52.         Dim drive As String
  53.         Dim drivetype As Long
  54.  
  55.         pos = 1
  56.  
  57.         Do While Not Mid$(strDrives, pos, 1) = Chr(0)
  58.             drive = Mid$(strDrives, pos, 3)
  59.             pos = pos + 4
  60.             drivetype = GetDriveType(drive)
  61.             If drivetype = DRIVE_CDROM Then
  62.                 MsgBox "CD-ROM found at drive " & UCase(drive)
  63.             End If
  64.         Loop
  65.     End If
  66. End Sub
Regards
>> ALI <<
Feb 25 '08 #1
0 3813

Sign in to post your reply or Sign up for a free account.

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
6
by: Gustav Medler | last post by:
Hello, there is a known problem with Opera and the execution of content shown in <NOSCRIPT> tag. Everythings works fine, if there is only one simple script like:...
18
by: Mickey Segal | last post by:
On comp.lang.java.programmer we are discussing problems created for Java programs by pop-up blockers (in the thread "showDocument blocked by new microsoft pop-up blocker"). Our problem is that...
8
by: R. Smits | last post by:
I've have got this script, the only thing I want to be changed is the first part. It has to detect IE version 6 instead of just "Microsoft Internet Explorer". Can somebody help me out? I tried...
7
by: mosaic | last post by:
Hi, all I really interested in how to check the memory leak of a program. Your smart guys, do you have excellent ideas that could share with me? Thank you. The following is my idea: In C...
22
by: Luke Matuszewski | last post by:
We all know that feature detection technique works from very beggining of user-agents supporting JavaScript. We can alway check if eg. document has a write property or smth else: ...
13
by: Matik | last post by:
Hello everybody, First: SQL Server 2000 sp3a, HP cluster server, MS 2003 server, database recovery model simple Torn page detection: When I have this option turned on, processes conected with...
0
by: darrenhello | last post by:
hi there, I am doing my last year's project and I have a 'little' problem. I have to do an edge detection filter. for now, some normal edge detection filters that I used worked fine but there a...
0
by: origami.takarana | last post by:
Intrusion Detection Strategies ----------------------------------- Until now, we’ve primarily discussed monitoring in how it relates to intrusion detection, but there’s more to an overall...
10
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.