From: Jason on
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?



From: Richard Mueller [MVP] on

"Jason" <nospam(a)spam.com> wrote in message
news:e3ScMUhxKHA.1692(a)TK2MSFTNGP04.phx.gbl...
> 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
--


From: Jason on
Thats, that works.



"Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in
message news:upQO$whxKHA.3408(a)TK2MSFTNGP06.phx.gbl...
>
> "Jason" <nospam(a)spam.com> wrote in message
> news:e3ScMUhxKHA.1692(a)TK2MSFTNGP04.phx.gbl...
>> 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
> --
>
>