Jump to content

How to tell if a drive letter is mounted?


Mbee
 Share

Go to solution Solved by ioa747,

Recommended Posts

I know how to use DriveGetDrive() to get an array enumerating all (or some) drives on the system. But I also need to know if the various drive letters hold mounted volumes or are otherwise available to be used to mount new volumes. But not only can't I find an AutoIt function or UDF for this purpose, I can't even find a WinAPI function that will give me this information.

The DriveGetType() function is useful, but if, say, the type is "Removable", how can I know if it holds a mounted volume? I could get the volume label, but do all mounted volumes have a label? Couldn't the label be blank?

I'm not sure if the DriveStatus() function will reliably tell me what I need to know. For example, if it returns "UNKNOWN", whether that drive letter has a RAW volume mounted or not is ambiguous.

If I knew of a function to mount a drive/volume, I suppose I could try to mount something and if it fails, one error return possibility would be something like "Drive already mounted", but I can't find a Mount() function either.

How can I accomplish what I need, please?  Thanks!

Link to comment
Share on other sites

#include <WinAPIFiles.au3>

_WinAPI_GetDriveNumber ( $sDrive )

_WinAPI_GetDriveType ( [$sDrive = ''] )

_WinAPI_GetVolumeInformation ( [$sRoot = ''] )

_WinAPI_SetVolumeMountPoint ( $sFilePath, $sGUID )

_WinAPI_GetVolumeNameForVolumeMountPoint ( $sMountedPath )



DriveGetType ( "path" [, operation = 1] )

DriveStatus ( "path" )

DriveGetSerial ( "path" )

DriveMapGet ( "device" )

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

  • Solution

i think with If FileExists("E:\") you can check if is in use

#include <WinAPIFiles.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $idListBox, $CurPos, $CurDRIVE

    ; Create GUI
    GUICreate("List Box DRIVES", 400, 296)
    $idListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($WS_VSCROLL, $WS_BORDER, $LBS_NOTIFY))
    GUICtrlSetFont(-1, 12, 400, 0, "Tahoma")
    GUISetState(@SW_SHOW)

    _GUICtrlListBox_Dir($idListBox, "", $DDL_DRIVES, False)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idListBox
                $CurPos = _GUICtrlListBox_GetCurSel($idListBox)
                $CurDRIVE = _GUICtrlListBox_GetText($idListBox, $CurPos)
                ;------------------------------------------------------------
                ConsoleWrite('****************************' & @CRLF)
                ConsoleWrite($CurDRIVE)

                If FileExists($CurDRIVE & "\") Then
                    ConsoleWrite(" FileExists " & @CRLF)
                    Local $aData = _WinAPI_GetDiskFreeSpaceEx($CurDRIVE & "\")
                    ConsoleWrite('Total free space on ' & $CurDRIVE & "\" & ' => ' & $aData[2] & ' bytes' & @CRLF)
                Else
                    ConsoleWrite(" File Not Exists " & @CRLF)
                EndIf

                ;------------------------------------------------------------
                Local $sMessage, $iTypeOfDrive = _WinAPI_GetDriveType($CurDRIVE & "\")
                Switch $iTypeOfDrive
                    Case $DRIVE_UNKNOWN
                        $sMessage = "The drive type cannot be determined."
                    Case $DRIVE_NO_ROOT_DIR
                        $sMessage = "The root path is invalid."
                    Case $DRIVE_REMOVABLE
                        $sMessage = "The drive is removable media."
                    Case $DRIVE_FIXED
                        $sMessage = "The drive is a fixed drive."
                    Case $DRIVE_REMOTE
                        $sMessage = "The drive is a remote (network) drive."
                    Case $DRIVE_CDROM
                        $sMessage = "The drive is a CD-ROM drive."
                    Case $DRIVE_RAMDISK
                        $sMessage = "The drive is a RAM disk."
                EndSwitch
                ConsoleWrite($sMessage & @CRLF)
                ;------------------------------------------------------------
                Local $aData = _WinAPI_GetVolumeInformation($CurDRIVE & "\")
                If Not @error Then
                    ConsoleWrite('Volume name: ' & $aData[0] & @CRLF)
                    ConsoleWrite('File system: ' & $aData[4] & @CRLF)
                    ConsoleWrite('Serial number: ' & $aData[1] & @CRLF)
                    ConsoleWrite('File name length: ' & $aData[2] & @CRLF)
                    ConsoleWrite('Flags: 0x' & Hex($aData[3]) & @CRLF)
                EndIf
                ;------------------------------------------------------------


                ConsoleWrite("" & @CRLF)

        EndSwitch
    WEnd

    GUIDelete()
EndFunc   ;==>Example

 

I know that I know nothing

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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