TheSwamp

Code Red => VB(A) => Topic started by: Kheilmann on December 22, 2006, 03:53:13 PM

Title: Map & Disconnect Drives
Post by: Kheilmann on December 22, 2006, 03:53:13 PM
Is it possible to map & disconnect a \\Server\Folder\ to/from a drive letter?


Title: Re: Map & Disconnect Drives
Post by: David Hall on December 22, 2006, 04:35:29 PM
this might get you started
Code: [Select]
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set AllDrives = WshNetwork.EnumNetworkDrives()

DriveLetter = "N:" 'must be capitalized
RemotePath = "\\server\share"

AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2
If AllDrives.Item(i) = DriveLetter Then AlreadyConnected = True
Next

If AlreadyConnected = False then
WShNetwork.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp "Drive " & DriveLetter & " connected successfully."
Else
WShNetwork.RemoveNetworkDrive DriveLetter
WshShell.PopUp "Drive " & DriveLetter & " disconnected."
End if
Title: Re: Map & Disconnect Drives
Post by: jjs on March 02, 2007, 01:16:03 AM
Is it possible to map & disconnect a \\Server\Folder\ to/from a drive letter?





YES.
Sorry, could not resist. I have a whole app that does this. You can use an INI file to load the paths you want and then map and unmap which ones you want by checking the boxes. Let me know if you are interested and I will see if I can find the code.