Windows Vista Forums

Find a unused drive letter

  1. #1


    Jason Guest

    Find a unused drive letter

    Hello

    I've got a to use the subst cmd on a PC, and when the script is run I won't
    know what drives are mapped at that time, so I'd like to be able to find a
    letter that isn't mapped, then I'll just use that in the subst cmd.

    My question, is how do i find a drive letter that isn't mapped?




      My System SpecsSystem Spec

  2. #2


    Richard Mueller [MVP] Guest

    Re: Find a unused drive letter


    "Jason" <nospam@newsgroup> wrote in message
    news:e3ScMUhxKHA.1692@newsgroup

    > Hello
    >
    > I've got a to use the subst cmd on a PC, and when the script is run I
    > won't know what drives are mapped at that time, so I'd like to be able to
    > find a letter that isn't mapped, then I'll just use that in the subst cmd.
    >
    > My question, is how do i find a drive letter that isn't mapped?
    >
    The Drives collection of the FileSystemObject is a collection of all known
    drives. You could enumerate all drives, network and local, with:
    =======
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    For Each objDrive In objFSO.Drives
    Wscript.Echo objDrive.DriveLetter & ", " & objDrive.Path
    Next
    =======
    You could setup a dictionary object of known letters, then test a letter to
    see if it is used. Better might be to just test using the DriveExists
    method. For example:
    =========
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If (objFSO.DriveExists("K:") = False) Then
    ' Drive K: is not used.
    Next
    ========
    You could even loop through several candidate letters until you find one
    available. For example:
    =========
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    arrDrives = Array("K:", "M:", "J:", "E:", "N:")
    For Each strDrive In arrDrives
    If (objFSO.DriveExists(strDrive) = False) Then
    strAvailable = strDrive
    Exit For
    End If
    Next
    =======
    The value of strAvailable will be the first drive letter available. If it is
    blank, none are available.

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --



      My System SpecsSystem Spec

  3. #3


    Jason Guest

    Re: Find a unused drive letter

    Thats, that works.



    "Richard Mueller [MVP]" <rlmueller-nospam@newsgroup> wrote in
    message news:upQO$whxKHA.3408@newsgroup

    >
    > "Jason" <nospam@newsgroup> wrote in message
    > news:e3ScMUhxKHA.1692@newsgroup

    >> Hello
    >>
    >> I've got a to use the subst cmd on a PC, and when the script is run I
    >> won't know what drives are mapped at that time, so I'd like to be able to
    >> find a letter that isn't mapped, then I'll just use that in the subst
    >> cmd.
    >>
    >> My question, is how do i find a drive letter that isn't mapped?
    >>
    >
    > The Drives collection of the FileSystemObject is a collection of all known
    > drives. You could enumerate all drives, network and local, with:
    > =======
    > Set objFSO = CreateObject("Scripting.FileSystemObject")
    > For Each objDrive In objFSO.Drives
    > Wscript.Echo objDrive.DriveLetter & ", " & objDrive.Path
    > Next
    > =======
    > You could setup a dictionary object of known letters, then test a letter
    > to see if it is used. Better might be to just test using the DriveExists
    > method. For example:
    > =========
    > Set objFSO = CreateObject("Scripting.FileSystemObject")
    > If (objFSO.DriveExists("K:") = False) Then
    > ' Drive K: is not used.
    > Next
    > ========
    > You could even loop through several candidate letters until you find one
    > available. For example:
    > =========
    > Set objFSO = CreateObject("Scripting.FileSystemObject")
    > arrDrives = Array("K:", "M:", "J:", "E:", "N:")
    > For Each strDrive In arrDrives
    > If (objFSO.DriveExists(strDrive) = False) Then
    > strAvailable = strDrive
    > Exit For
    > End If
    > Next
    > =======
    > The value of strAvailable will be the first drive letter available. If it
    > is blank, none are available.
    >
    > --
    > Richard Mueller
    > MVP Directory Services
    > Hilltop Lab - http://www.rlmueller.net
    > --
    >
    >


      My System SpecsSystem Spec


Find a unused drive letter
Similar Threads
Thread Forum
Re: How to manage disk drive letter when conflicting with network drive ? Server General
Find my current drive letter and execute a program from it while i VB Script
Phantom CD Drive after reassigning Recovery Partition drive letter Vista installation & setup
LastWriteTime and Locating the drive letter of a flash drive. PowerShell
USB drive letters and mapped drive letter issues Vista hardware & devices