Results 1 to 3 of 3

Thread: USB Serial errors

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    362

    USB Serial errors

    basically i use a USB serial number security function where the user must have the USB drive inserted into their machine for my app to load.

    on my machine this functions perfectly within a timley manner (couple of seconds) both in reporting an error if the drive is missing or moving on if its present. However on a users/clients machine if the USB is missing the app does not crash but takes it sweet time to report the USB missing, and ultimatley the user gets jack of waiting for it so they alt+ctl+del out of my app.

    am i missing something, is this a bad idea for security?? or am i able to excluded particular drives from the serial number scan like A: and C: etc to save time..........................???

    my code looks like this

    Code:
        If LicenseInfo.blnLoadNormal = True Then
            txtValidationKey.Visible = True
            Timer3.Enabled = False
              Dim X As Integer
              Dim Serial As Long
              Dim VName As String
              Dim FSName As String
              Dim ret As Integer
              For X = 0 To Drive1.ListCount - 1
                  Serial = 0
                  VName = String$(255, Chr$(0))
                  FSName = String$(255, Chr$(0))
                  GetVolumeInformation Drive1.List(X) & "\", VName, 255, Serial, 0, 0, FSName, 255
                  If Serial = CorrectSerial Then
                      GoTo CorrectDriveInserted
                  Else
                    If Serial = VDMasterSerial Then
                        GoTo CorrectDriveInserted
                    End If
                  End If
              Next X
              'Correct usb drive wasnt found, tell them, then exit the sub
              ret = MsgBox("Please insert the correct Software Key and Restart the program", vbOKOnly, "Incorrect Software Key")
              End
        Else
            Timer3.Enabled = False
            Exit Sub
        End If
    
    CorrectDriveInserted:
        LicenseInfo.strUSBDriveLetter = Drive1.List(X) 'this assigns the USB Key Drive letter to the Variable in mod LicenseInfo
        CheckUpdate
    cheers
    Last edited by aztrix; Dec 19th, 2007 at 04:21 AM.

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

    Re: USB Serial errors

    am i able to excluded particular drives from the serial number scan like A: and C: etc to save time..........................???
    yes you can get all the drives, then the type of the drive, you can then exclude fixed drive and cds
    vb Code:
    1. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    2. Private Sub Form_Load()
    3.     'KPD-Team 1998
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     Dim strSave As String
    7.     'Set the graphic mode to persistent
    8.     Me.AutoRedraw = True
    9.     'Create a buffer to store all the drives
    10.     strSave = String(255, Chr$(0))
    11.     'Get all the drives
    12.     ret& = GetLogicalDriveStrings(255, strSave)
    13.     'Extract the drives from the buffer and print them on the form
    14.     For keer = 1 To 100
    15.         If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
    16.         Me.Print Left$(strSave, InStr(1, strSave, Chr$(0)) - 1)
    17.         strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
    18.     Next keer
    19. End Sub
    20. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    21. Private Sub Form_Load()
    22.     'KPD-Team 1998
    23.     'URL: [url]http://www.allapi.net/[/url]
    24.     'E-Mail: [email][email protected][/email]
    25.     'Set the graphic mode to persistent
    26.     Me.AutoRedraw = True
    27.     'Get information about the C:\
    28.     Select Case GetDriveType("C:\")
    29.         Case 2
    30.             Me.Print "Removable"
    31.         Case 3
    32.             Me.Print "Drive Fixed"
    33.         Case Is = 4
    34.             Me.Print "Remote"
    35.         Case Is = 5
    36.             Me.Print "Cd-Rom"
    37.         Case Is = 6
    38.             Me.Print "Ram disk"
    39.         Case Else
    40.             Me.Print "Unrecognized"
    41.     End Select
    42. End Sub
    and exclude A: anyway
    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    362

    Re: USB Serial errors

    cheers westconn1 ill give it a try, hopefully this will fasten it up on client machines.

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