Find a unused drive letter


  1.    17 Mar 2010 #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.    17 Mar 2010 #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.    18 Mar 2010 #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
Removing External drive with Ubuntu OS but no drive letter designation
I have a wierd problem that most of the suggestions seem not to work. I have a HP computer with Vista basic installed at factory with no disc sent...
General Discussion
Re: How to manage disk drive letter when conflicting with network drive ?
Most of them are using SP3. Are you sure that the problem adressed in SP3 is the same as the situation quoted here ? Thank you ! -- Eric
Server General
Find my current drive letter and execute a program from it while i
HI! The problem is that when i change the directory to usbletter:\SYSTEM i can't find a way to execute a program from the source directory where...
VB Script
Flash Drive has no drive letter... Not in Disk Management
Hi guys, Im hoping someone will be able to help me here... I recently fresh installed my Vista Premium x86 on my homebuilt, and I had all my...
Vista hardware & devices
Phantom CD Drive after reassigning Recovery Partition drive letter
Another annoying Vista mystery. I just got a new HP Vista desktop -- I already have an HP Vista laptop. On both, HP provided a Recovery-Image...
Vista installation & setup
LastWriteTime and Locating the drive letter of a flash drive.
Part 1 Is the Get-ChildItem property 'lastwritetime' equivalent to explorer's 'Date Modified'? Part 2 I am running Windows XP. I back up my...
PowerShell
USB drive letters and mapped drive letter issues
In Windows XP, I always had problems with clients who wanted to use USB drives in a corporate environment where drives are mapped via scripts to low...
Vista hardware & devices

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • Old server
    About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 17:37.
    .