Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
prolinkdata_gr Trusted Contributor.
Trusted Contributor.
1937 views

GetDriveType

Jump to solution

Hi all,

I would like to identify if  a disk is removable or fixed. I found that the relative function is "GetDriveType" but I couldn't make it work...

Thank you

0 Likes
1 Solution

Accepted Solutions
JGramer Frequent Contributor.
Frequent Contributor.

RE: GetDriveType

Jump to solution

Below is an example program showing how to use the GetDriveType function.
I hope it helps you.

---------------------------------------------------

IDENTIFICATION DIVISION.

PROGRAM-ID. getdrivetype.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SPECIAL-NAMES.

    CRT STATUS IS CRT-STATUS

    SCREEN CONTROL IS SCREEN-CONTROL

    EVENT STATUS IS EVENT-STATUS.

/

WORKING-STORAGE SECTION.

01  RETURN-VALUE                USAGE UNSIGNED-LONG.

01  MY-DRIVE                    PIC X(255) VALUE SPACES.

01  CRT-STATUS                  PIC 9(5).

01  SCREEN-CONTROL.

    03  ACCEPT-CONTROL          PIC 9.

    03  CONTROL-VALUE           PIC 999.

    03  CONTROL-HANDLE          USAGE HANDLE.

    03  CONTROL-ID              PIC X(2) COMP-X.

01  EVENT-STATUS.

    03  EVENT-TYPE              PIC X(4) COMP-X.

    03  EVENT-WINDOW-HANDLE     USAGE HANDLE.

    03  EVENT-CONTROL-HANDLE    USAGE HANDLE.

    03  EVENT-CONTROL-ID        PIC X(2) COMP-X.

    03  EVENT-DATA-1            USAGE SIGNED-SHORT.

    03  EVENT-DATA-2            USAGE SIGNED-LONG.

    03  EVENT-ACTION            PIC X COMP-X.

 

PROCEDURE DIVISION.

MAINLINE SECTION.

    SET ENVIRONMENT "DLL-CONVENTION" TO 1.

    CALL "KERNEL32.DLL".

    MOVE "C:\" TO MY-DRIVE.

    INSPECT MY-DRIVE REPLACING TRAILING SPACES BY NULLS.

    CALL "GetDriveTypeA" USING BY REFERENCE MY-DRIVE RETURNING RETURN-VALUE.

    IF RETURN-VALUE = 0

       DISPLAY MESSAGE BOX "The drive type cannot be determined."

         TITLE "Drive Unknown"

    END-IF.

    IF RETURN-VALUE = 1

       DISPLAY MESSAGE BOX "The root path is invalid; for example, there is "

         "no volume mounted at the specified path." TITLE "Drive No Root Dir"

    END-IF.

    IF RETURN-VALUE = 2

       DISPLAY MESSAGE BOX "The drive has removable media; for example, a "

         "floppy drive, thumb drive, or flash card reader."

         TITLE "Drive Removable"

    END-IF.

    IF RETURN-VALUE = 3

       DISPLAY MESSAGE BOX "The drive has fixed media; for example, a hard "

         "disk drive or flash drive." TITLE "Drive Fixed"

    END-IF.

    IF RETURN-VALUE = 4

       DISPLAY MESSAGE BOX "The drive is a remote (network) drive."

         TITLE "Drive Remote"

    END-IF.

    IF RETURN-VALUE = 5

       DISPLAY MESSAGE BOX "The drive is a CD-ROM drive."

         TITLE "Drive CD-ROM"

    END-IF.

    IF RETURN-VALUE = 6

       DISPLAY MESSAGE BOX "The drive is a RAM disk."

         TITLE "Drive RAM Disk"

    END-IF.

    CANCEL "KERNEL32.DLL".

ML20.

    EXIT PROGRAM.

ML30.

    STOP RUN.

View solution in original post

0 Likes
2 Replies
JGramer Frequent Contributor.
Frequent Contributor.

RE: GetDriveType

Jump to solution

Below is an example program showing how to use the GetDriveType function.
I hope it helps you.

---------------------------------------------------

IDENTIFICATION DIVISION.

PROGRAM-ID. getdrivetype.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SPECIAL-NAMES.

    CRT STATUS IS CRT-STATUS

    SCREEN CONTROL IS SCREEN-CONTROL

    EVENT STATUS IS EVENT-STATUS.

/

WORKING-STORAGE SECTION.

01  RETURN-VALUE                USAGE UNSIGNED-LONG.

01  MY-DRIVE                    PIC X(255) VALUE SPACES.

01  CRT-STATUS                  PIC 9(5).

01  SCREEN-CONTROL.

    03  ACCEPT-CONTROL          PIC 9.

    03  CONTROL-VALUE           PIC 999.

    03  CONTROL-HANDLE          USAGE HANDLE.

    03  CONTROL-ID              PIC X(2) COMP-X.

01  EVENT-STATUS.

    03  EVENT-TYPE              PIC X(4) COMP-X.

    03  EVENT-WINDOW-HANDLE     USAGE HANDLE.

    03  EVENT-CONTROL-HANDLE    USAGE HANDLE.

    03  EVENT-CONTROL-ID        PIC X(2) COMP-X.

    03  EVENT-DATA-1            USAGE SIGNED-SHORT.

    03  EVENT-DATA-2            USAGE SIGNED-LONG.

    03  EVENT-ACTION            PIC X COMP-X.

 

PROCEDURE DIVISION.

MAINLINE SECTION.

    SET ENVIRONMENT "DLL-CONVENTION" TO 1.

    CALL "KERNEL32.DLL".

    MOVE "C:\" TO MY-DRIVE.

    INSPECT MY-DRIVE REPLACING TRAILING SPACES BY NULLS.

    CALL "GetDriveTypeA" USING BY REFERENCE MY-DRIVE RETURNING RETURN-VALUE.

    IF RETURN-VALUE = 0

       DISPLAY MESSAGE BOX "The drive type cannot be determined."

         TITLE "Drive Unknown"

    END-IF.

    IF RETURN-VALUE = 1

       DISPLAY MESSAGE BOX "The root path is invalid; for example, there is "

         "no volume mounted at the specified path." TITLE "Drive No Root Dir"

    END-IF.

    IF RETURN-VALUE = 2

       DISPLAY MESSAGE BOX "The drive has removable media; for example, a "

         "floppy drive, thumb drive, or flash card reader."

         TITLE "Drive Removable"

    END-IF.

    IF RETURN-VALUE = 3

       DISPLAY MESSAGE BOX "The drive has fixed media; for example, a hard "

         "disk drive or flash drive." TITLE "Drive Fixed"

    END-IF.

    IF RETURN-VALUE = 4

       DISPLAY MESSAGE BOX "The drive is a remote (network) drive."

         TITLE "Drive Remote"

    END-IF.

    IF RETURN-VALUE = 5

       DISPLAY MESSAGE BOX "The drive is a CD-ROM drive."

         TITLE "Drive CD-ROM"

    END-IF.

    IF RETURN-VALUE = 6

       DISPLAY MESSAGE BOX "The drive is a RAM disk."

         TITLE "Drive RAM Disk"

    END-IF.

    CANCEL "KERNEL32.DLL".

ML20.

    EXIT PROGRAM.

ML30.

    STOP RUN.

View solution in original post

0 Likes
prolinkdata_gr Trusted Contributor.
Trusted Contributor.

RE: GetDriveType

Jump to solution

that worked, thank you!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.