Forum Discussion

AndersW's avatar
AndersW
Occasional Contributor
14 years ago

Need to find Label or Serial for removable drive(s)

TC version: 7.52

Script language: Delphi



I am currently making some tests for accessing a removable drive to read a file on it.



Problem is, that I can't be certain that the drive always gets the same drive letter.



So I need to find a unique identifier for it. This could either be the Label for the drive, or the serial. I had a look into the aqFileSystems.Drives property, I can see that it is possible to find a drive's serial. I used the following call:



drv := aqFileSystem.Drives(0).SerialNumber;



But all I get in return is 'Unknown'. If I Inspect the object aqFileSystem.Drives(0), I can see that serial contains a value.



If I use aqFileSystem.Drives(0).DriveLetter, then I get the value shown for that property.



How do I extract the Serial value?? ... or is it at all possible to find the drive's label instead??



Any help would be appreciated.

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Anders,



    Log.Message(aqFileSystem.Drives(1).SerialNumber);

    works fine for me.

    Maybe the reason of your problem is that Drives(0) corresponds to the A: drive which is empty?
  • Hi Anders,



    This issue is solved in TC 8.



    For TC 7, you need to convert the returned value to float (VarToFloat) or to string (VarToStr). For example:

    drv := aqConvert.VarToFloat(aqFileSystem.Drives(0).SerialNumber)


    See the aqDriveInfo.SerialNumber help topic.
  • AndersW's avatar
    AndersW
    Occasional Contributor
    Hey there



    Thanks for that ... seems to be working like a charm for v7.52 when converting to float.



    A related question. My test pc has several network drives that are sometimes offline. As I want to find that specific removable drive, I was planning to just make a drive count and then look at each of them.



    This doesn't work for offline network drives, as I can't get that info. Is there a way to disregard the network drives?



    I can see the drive type. Problem is, that I have no idea what they
    are. I am guessing they specify whether it is removable, fixed,
    network, cd or ram drive. But is that true, and which is indicated with
    each value?



    A quick google search only revealed this for VBScript:

    0 = Unknown

    1 = Removable

    2 = Fixed

    3 = Network

    4 = CD-ROM

    5 = RAM Disk



    Doesn't seem to be exactly that here, as my network drives are '4'.
  • Hi Anders,



    You can check drive type by using the DriveType property.



    Here is an example (avoiding remote drives):

    function DriveTypeExample;

    var i, colDrives: OleVariant;

    begin

      colDrives := aqFileSystem.Drives;

      for i := 0 to colDrives.Count-1 do

      begin

        if colDrives.Item(i).DriveType <> 4 then

          Log.Message(ColDrives.Item(i).DriveLetter);

      end;

    end;