How to get the drive letter of the drive?

zhaozj2021-02-11  268

Option ExplicitPrivate Declare Function GetDriveType Lib "kernel32" Alias ​​"GetDriveTypeA" _ (ByVal nDrive As String) As Long'GetLogicalDriveStrings -> Get a string, which contains the current root drive path all logical drives Private Declare Function GetLogicalDriveStrings Lib "kernel32 "Alias" getLogicalDriveStrings "_ (Byval NBufferLength As Long, Byval LpBuffer AS String) AS Long

Private const drive_removable = 2Private const drive_fixed = 3private const drive_remote = 4Private const drive_cdrom = 5private const drive_ramdisk = 6

Private Sub Command1_Click () Dim rtn As StringDim AllDrives As StringDim JustOneDrive As StringAllDrives = Space $ (64) 'a buffer rtn = GetLogicalDriveStrings (Len (AllDrives), AllDrives)' call the function to get every drive string AllDrives = Left (AllDrives , RTN) DO RTN = INSTR (alldrives, chr (0)) if q = = left (allDrives) alldrives = MID (AllDrives, RTN 1, Len (allDrives) = GetDriveType JustOneDrive) 'to check the type of drive If rtn = DRIVE_CDROM Then' is a CD-ROM Label1.Caption = Left (UCase (JustOneDrive), 2) 'to label1 Exit Do End If End IfLoop Until AllDrives = "" Or rtn = DRIVE_CDROMCommand1.Enabled = Falseif label1.caption = "" "" "" "" "End iFend Sub"

转载请注明原文地址:https://www.9cbs.com/read-4304.html

New Post(0)