Answer the question
In order to leave comments, you need to log in
How to automatically assign a free letter to a network drive in a VBS script?
Good day! There is a script for connecting network drives:
On Error Resume Next
Set objWshNetwork = CreateObject( "WScript.Network" )
Set objShell = CreateObject("Shell.Application")
MapDrive "V:", "\\ftech", "FTech"
Sub MapDrive(strDrive, strPath, strName)
On Error Resume Next
objWshNetwork.RemoveNetworkDrive strDrive, vbTrue, vbTrue
objWshNetwork.MapNetworkDrive strDrive, strPath, vbTrue
objShell.NameSpace(strDrive).Self.Name = strName
End Sub
Answer the question
In order to leave comments, you need to log in
You will have to sort through all the letters until you find a free one.
Example :
strUNC = "\\server\share"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive AvailableDriveLetter, strUNC
'--------------------- ----------------------------
Function AvailableDriveLetter
With CreateObject("Scripting.FileSystemObject")
For i = Asc("D") To Asc ("Z")
If Not .DriveExists(Chr(i)) Then
AvailableDriveLetter = Chr(i) & ":"
Exit For
End If
Next
End With
End Function
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question