Results 1 to 9 of 9

Thread: [RESOLVED] get usb flash drive letter

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] get usb flash drive letter

    i want to get the drive letter of the newly inserted USB flash drive in the form like E:, F: .
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: get usb flash drive letter

    Quote Originally Posted by isnoend07
    i want to get the drive letter of the newly inserted USB flash drive in the form like E:, F: .
    Put a DriveList Box on your form and refresh the list with a TimerControl.
    EDIT: You can also refresh the list in the DriveList's Click event.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: get usb flash drive letter

    vb Code:
    1. Dim r&, allDrives$, JustOneDrive$, pos%, DriveType&
    2.       Dim aronedrive() As String
    3.       allDrives$ = Space$(64)
    4.       r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)
    5.       allDrives$ = Left$(allDrives$, r&)
    6.       aronedrive = Split(allDrives, vbNullChar)
    7.       For d = UBound(aronedrive) To 1 Step -1
    8.           If getdrivetype(aronedrive(d)) = DRIVE_REMOTE Then stickid = aronedrive(d): Exit For
    9.       Next
    change drive_remote to drive_removable
    declare all the api functions and constants
    it will find the removable drive with the highest drive letter
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: get usb flash drive letter

    Quote Originally Posted by westconn1
    vb Code:
    1. Dim r&, allDrives$, JustOneDrive$, pos%, DriveType&
    2.       Dim aronedrive() As String
    3.       allDrives$ = Space$(64)
    4.       r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)
    5.       allDrives$ = Left$(allDrives$, r&)
    6.       aronedrive = Split(allDrives, vbNullChar)
    7.       For d = UBound(aronedrive) To 1 Step -1
    8.           If getdrivetype(aronedrive(d)) = DRIVE_REMOTE Then stickid = aronedrive(d): Exit For
    9.       Next
    change drive_remote to drive_removable
    declare all the api functions and constants
    it will find the removable drive with the highest drive letter
    Thanks, thats what i needed
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: get usb flash drive letter

    Interesting. What API is this code used with?
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: get usb flash drive letter

    Quote Originally Posted by CDRIVE
    Interesting. What API is this code used with?
    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

    Const DRIVE_REMOVABLE = 2
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: get usb flash drive letter

    Quote Originally Posted by isnoend07
    Private Declare Function GetDriveType Lib "kernel32"
    Dunka Grazzi and thanks!!
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: get usb flash drive letter

    Quote Originally Posted by CDRIVE
    Interesting. What API is this code used with?
    Have a read of API-Guide Chris.

    GetDriveType
    The GetDriveType function determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.

    GetLogicalDriveStrings
    The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  9. #9
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: get usb flash drive letter

    Quote Originally Posted by Keithuk
    Have a read of API-Guide Chris.
    Yeah Keith, I read the API guide after isnoend07 posted the API,s.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width