Kbase 17121: How to Call WIN32 API Function: GetDriveType
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
How to Call WIN32 API Function: GetDriveType
DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.
INTRODUCTION:
=============
The following sample code shows how to call the Win32 API function
called GetDriveType. This function returns the type of a drive for
a given root path name.
This code has been tested on Window NT 4.0 Workstation only.
&GLOBAL-DEFINE DRIVE_UNKNOWN 0
&GLOBAL-DEFINE DRIVE_NO_ROOT_DIR 1
&GLOBAL-DEFINE DRIVE_REMOVABLE 2
&GLOBAL-DEFINE DRIVE_FIXED 3
&GLOBAL-DEFINE DRIVE_REMOTE 4
&GLOBAL-DEFINE DRIVE_CDROM 5
&GLOBAL-DEFINE DRIVE_RAMDISK 6
&GLOBAL-DEFINE DRIVE_LETTERS "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DEFINE VARIABLE chrRootPathName AS CHARACTER NO-UNDO FORMAT "X(4)".
DEFINE VARIABLE chrResults AS CHARACTER NO-UNDO EXTENT 7.
DEFINE VARIABLE chrDriveLetter AS CHARACTER NO-UNDO FORMAT "X(1)".
DEFINE VARIABLE intDriveType AS INTEGER NO-UNDO.
DEFINE VARIABLE intIndex AS INTEGER NO-UNDO.
PROCEDURE GetDriveTypeA EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER chrRootPathName AS CHARACTER.
DEFINE RETURN PARAMETER intDriveType AS LONG.
END PROCEDURE.
DO intIndex = 1 TO 26:
ASSIGN chrDriveLetter = SUBSTRING({&DRIVE_LETTERS},intIndex,1).
RUN GetDriveTypeA (INPUT chrDriveLetter + ":\\",
OUTPUT intDriveType).
ASSIGN intDriveType = intDriveType + 1
chrResults[intDriveType] = chrResults[intDriveType] + " " +
chrDriveLetter.
END.
MESSAGE "Results:" SKIP SKIP
"Unknown: " + TRIM(chrResults[1]) SKIP
"Does Not Exist: " + TRIM(chrResults[2]) SKIP
"Floppy Disk: " + TRIM(chrResults[3]) SKIP
"Hard Disk: " + TRIM(chrResults[4]) SKIP
"Network Drive: " + TRIM(chrResults[5]) SKIP
"Compact Disk: " + TRIM(chrResults[6]) SKIP
"Memory: " + TRIM(chrResults[7]) VIEW-AS ALERT-BOX.
Progress Software Technical Support Note # 17121