|
-
Sep 19th, 2000, 02:05 AM
#1
Thread Starter
Hyperactive Member
How can i check to see, if any, cd is in the cd drive, and if there is a cd in the drive, what cd it is?
-
Sep 19th, 2000, 03:46 AM
#2
Frenzied Member
try this:
Code:
Option Explicit
Private Sub Command1_Click()
On Error GoTo errHan:
Dim strLabel As String
' check there is a cd in the drive
Dir "d:\"
' should be 0
strLabel = Dir("d:\", vbVolume)
If strLabel = "" Then
MsgBox "CD has no label"
Else
MsgBox "D drive contains: " & strLabel
End If
Exit Sub
errHan:
' no cd in drive
MsgBox Err.Number & " " & Err.Description
End Sub
[Edited by Mark Sreeves on 09-19-2000 at 04:50 AM]
-
Sep 19th, 2000, 04:19 AM
#3
Conquistador
way with api
Code:
'in a module
Public Declare Function GetVolumeInformation Lib "kernel32.dll" Alias _
"GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer _
As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
'on a command button
Dim volname As String
Dim sn As Long
Dim snstr As String
Dim maxcomplen As Long
Dim sysflags As Long
Dim sysname As String
Dim retval As Long
Private Sub Command1_Click()
volname = Space(256)
sysname = Space(256)
retval = GetVolumeInformation("D:\", volname, Len(volname), sn, maxcomplen, _
sysflags, sysname, Len(sysname))
volname = Trim$(volname)
sysname = Trim$(sysname)
snstr = Trim(Hex(sn))
snstr = String(8 - Len(snstr), "0") & snstr
snstr = Left(snstr, 4) & "-" & Right(snstr, 4)
Debug.Print "Volume Name: "; volname
Debug.Print "Serial Number: "; snstr
Debug.Print "File System: "; sysname
End Sub
this works too!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|