Jump to content

Recommended Posts

Posted

Given that I don't have a usb storage device and cannot test it for myself can anyone confirm that

$var = DriveGetSerial( "e:\" )

MsgBox(4096, "Serial Number: ", $var)

where "e:\" is mapped as the storage device will return a serial number that is unique to that device.

Cheers

Ant... :whistle:

Posted (edited)

I don't sure what are you asking, you like to know if this function is work? so yes, its work fine...

If you like to get serials number of all currently connected (founded) USB-Sticks, you can try somthing like that:

$USBSerials = _GetDrivesSerial("removable")
MsgBox(64, "USB SN", $USBSerials)

Func _GetDrivesSerial($Type)
    Local $DrivesArr = DriveGetDrive($Type), $SerialsString, $iDrv
    If IsArray($DrivesArr) Then
        For $iDrv = 1 To $DrivesArr[0]
            If $DrivesArr[$iDrv] <> "a:" And $DrivesArr[$iDrv] <> "b:" Then
                $SerialsString &= "The serial Number of USB Drive <" & StringUpper($DrivesArr[$iDrv]) & "\> is {" & _
                DriveGetSerial($DrivesArr[$iDrv]) & "}" & @CR
            EndIf
        Next
        Return $SerialsString
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc
Edited by MsCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MsCreatoR said:

I don't sure what are you asking, you like to know if this function is work? so yes, its work fine...

If you like to get serials number of all currently connected (founded) USB-Sticks, you can try somthing like that:

$USBSerials = _GetDrivesSerial("removable")
MsgBox(64, "USB SN", $USBSerials)

Func _GetDrivesSerial($Type)
    Local $DrivesArr = DriveGetDrive($Type), $SerialsString, $iDrv
    If IsArray($DrivesArr) Then
        For $iDrv = 1 To $DrivesArr[0]
            If $DrivesArr[$iDrv] <> "a:" And $DrivesArr[$iDrv] <> "b:" Then
                $SerialsString &= "The serial Number of USB Drive <" & StringUpper($DrivesArr[$iDrv]) & "\> is {" & _
                DriveGetSerial($DrivesArr[$iDrv]) & "}" & @CR
            EndIf
        Next
        Return $SerialsString
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc
If the serial number is a number unique to each usb storage device then I can have a script that will test that the device when inserted is a known and authorised device.

Thanks for your help with the code. I am encouraged to go and purchase the equipment and put it to the test.

Cheers Ant... :whistle:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...