⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check drives.bas

📁 I am sorry ,at first ,我上载了一个错误的文件
💻 BAS
字号:
Attribute VB_Name = "Module1"
'''''''''''''''''''''''''''''''''''''''''''
'By: Osama Abdel-Karim                    '
'email: eg_semsem@maktoob.com             '
'Visit my Programming site:               '
'                                         '
' http://programming_links.homestead.com  '
'                                         '
'''''''''''''''''''''''''''''''''''''''''''

Const CheckDrive_NotRem = 0
Const CheckDrive_RemAndFound = 1
Const CheckDrive_RemAndNotFound = 2
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long


'InPut: the letter of the drive to check it or the string "all" to check for all drives
Public Function CheckNow(strDrive As String)
        
    Dim strSave As String
    Dim strDriveName As String
    Dim Res, keer, DiskFound
    
    'Create a buffer to store all the drives
    strSave = String(255, Chr$(0))
    'Get all the drives
    ret& = GetLogicalDriveStrings(255, strSave)
    
    'Extract the drives from the buffer
    For keer = 1 To 100
        If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
        strDriveName = Left$(strSave, InStr(1, strSave, Chr$(0)) - 1)
        'Check the drive for type and diskettes
        If strDrive = "all" Then
            Res = CheckDrive(strDriveName)
            If Res = CheckDrive_RemAndNotFound Then
                MsgBox "No Disk in drive: " & strDriveName
            ElseIf Res = CheckDrive_RemAndFound Then
                MsgBox "There is a Disk in drive: " & strDriveName
            End If
        ElseIf (strDrive + ":\") = strDriveName Then
            Res = CheckDrive(strDriveName)
            If Res = CheckDrive_RemAndNotFound Then
                MsgBox "No Disk in drive: " & strDriveName
            ElseIf Res = CheckDrive_RemAndFound Then
                MsgBox "There is a Disk in drive: " & strDriveName
            ElseIf Res = CheckDrive_NotRem Then
                MsgBox "This isn't a removal or CD-Rom drive"
            End If
            DiskFound = True
            Exit For
        End If
        strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
    Next keer
    
    'Check whether there is a drive with the letter the user entered
    If (Not DiskFound) And (strDrive <> "all") Then MsgBox "No drive with this letter found!"
End Function

''''''''''''''''''''''''
'Task:
'1) Check whether the drive is removal or CD-Rom or not
'2) Check if there is a disk in the drive
'The idea depends on changing the directory to the drive
'path then check: if an error happens that means the program
'can't change the directory to the path of the disk.
'Consequently, there is no disk, and the function returns
'
'OutPut of CheckDrive:
'  0 = The drive isn't removal or CD-Rom
'  1 = There is a Disk in the drive
'  2 = There is no Disk in the drive
''''''''''''''''''''''''

Function CheckDrive(strDrive As String) As Integer
    On Error GoTo errhandler
    Select Case GetDriveType(strDrive)
        Case 2  ' Removal
            ChDir strDrive
            CheckDrive = CheckDrive_RemAndFound ' The drive is removal and there is a disk
            Exit Function
        Case 5  ' CD-Rom drive
            ChDir strDrive
            CheckDrive = CheckDrive_RemAndFound ' The drive is CD-Rom and there is a disk
            Exit Function
    End Select
    
Exit Function

errhandler:
    'there isn't a Disk in the drive
    If Err.Number = 75 Then CheckDrive = 2 'Path/access error

End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -