Identify USB drive or flash drive

111 views
Skip to first unread message

Yakano

unread,
Dec 5, 2022, 4:53:46 AM12/5/22
to Harbour Users
Hello

Until now it was enough for me to identify if the disk where the application resides is local or a network drive (using NetDisk() from C*Tools).

Does anyone know how to identify from Harbor if a unit is an external disk or a flash drive? 

Thank you!

Bernard Mouille

unread,
Dec 5, 2022, 7:00:12 AM12/5/22
to Harbour Users
Hello yakano,
If you use Windows you can take some idea in the attached code.
Regards,
Bernard.

Test.txt

Yakano

unread,
Dec 5, 2022, 10:55:13 AM12/5/22
to Harbour Users
Hello Berrnard

It looks like "InterfaceType" might help me with what I'm looking for. 

But how can I know which item corresponds to a certain drive letter? That is, how to know the "InterfaceType" of (for example) "X:"?

Regards.

Bernard Mouille

unread,
Dec 5, 2022, 2:02:11 PM12/5/22
to Harbour Users
Hello Yakano,

In the code, replace :
- classe = "Win32_DiskDrive"
with :
- classe = "Win32_LogicalDisk"

Replace if you want only 1 disk :
- Items     = oWMI:ExecQuery( 'Select * from ' + classe )
with :
- Items     = oWMI:ExecQuery( 'Select * from ' + classe + ' where DeviceID="c:"' )

"c:" = the disk that you want.

Regards,
Bernard.

Jose Antonio Leon Tellez

unread,
Dec 5, 2022, 5:47:14 PM12/5/22
to harbou...@googlegroups.com
Ho Yakano,

View:

***************************
FUNCTION units_usb()
***************************
aDrives := {}
FOR I:=1 TO 26
    cDrive := CHR(64+I)
    nTipo := DRIVETYPE(cDrive)
    DO CASE
       CASE nTipo = 0
            AADD(aDrives,cDrive+' '+'Disco RAM    ')
       CASE nTipo = 2
            IF !cDrive$'A|B'
               IF DISKREADY(cDrive,.F.)
                  AADD(aDrives,cDrive+' '+'Memoria USB  ')
               ENDIF
            ENDIF
       CASE nTipo = 3
            AADD(aDrives,cDrive+' '+'Disco Duro   ')
       CASE nTipo = 4
            AADD(aDrives,cDrive+' '+'CD ROM       ')
       CASE nTipo = 5
            AADD(aDrives,cDrive+' '+'Unidad de Red')
       otherwise
*           AADD(aDrives,cDrive+' '+'Desconocido  ')
    ENDCASE
NEXT
ASORT(aDrives,,,{|x,y|SUBSTR(x,3,5) < SUBSTR(y,3,5)})
*** in array  ADrives  ---> usb units
return


/*
* HB_ISREMOTEDISK( cDrv ) -> .T. if cDrv is a Remote Drive
* HB_ISRAMDISK( cDrv ) -> .T. if cDrv is a RAM Disk
* HB_ISHARDDISK( cDrv ) -> .T. if cDrv is a Hard Disk
* HB_ISCDROM( cDrv ) -> .T. if cDrv is a CDROM
* HB_ISDISKETTE( cDrv ) -> .T. if cDrv is a Floppy
* HB_DISKREADY( cDrv ) -> .T. if cDrv is a Floppy and ready to be written
* HB_DISKREADYW( cDrv ) -> same as HB_DISKREADY()

Could you please try to replace the functions in query with the new
ones?

ISDISK -> HB_ISDISKETTE
DISKREADY -> HB_DISKREADY
DISKREADYW -> HB_DISKREADYW
*/

Regards,


Jose Antonio Leon Tellez



--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/f8b4abb4-a62a-433b-b349-4cc00a044e56n%40googlegroups.com.

Yakano

unread,
Dec 6, 2022, 7:29:13 AM12/6/22
to Harbour Users
Hello Bernard

With the "Win32_LogicalDisk" class, the properties change, that is, "InterfaceType" does not appear, but thanks to the Miro$oft link that you include in your code, I have been able to verify that "DriveType" offers exactly the information I was looking for...

Select Case objDisk.DriveType 
  Case 1 Wscript.Echo "No root directory." 
  Case 2 Wscript.Echo "DriveType: Removable drive." 
  Case 3 Wscript.Echo "DriveType: Local hard disk." 
  Case 4 Wscript.Echo "DriveType: Network disk." 
  Case 5 Wscript.Echo "DriveType: Compact disk." 
  Case 6 Wscript.Echo "DriveType: RAM disk." 
  Case Else Wscript.Echo "Drive type could not be determined." 
End Select

Best regards
Je te remercie beaucoup !!!

Yakano

unread,
Dec 6, 2022, 7:51:48 AM12/6/22
to Harbour Users
Hello Juan Antonio 

I've tried your solution and it works too, although I must admit I was surprised that "DriveType()" returns "2" for a removable drive (USB, floppy drives are extinct). 

 In the official Harbour information itself, we can find in this link [https://harbour.github.io/doc/clct3.html#drivetype] and the returned values ​​should be different (or they have been updated and the correct information has not been found). 

I copy the info... 
    Code    Definition
    0       RAM Disk
    1       Floppy Disk (disk change cannot be established by system)
    2       Floppy Disk (disk change can be established by system)
    3       Hard Disk

 Best regards
Muchísimas gracias !!!
Reply all
Reply to author
Forward
0 new messages