473,432 Members | 1,709 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,432 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 3821

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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.