Author Topic: Map & Disconnect Drives  (Read 1857 times)

0 Members and 1 Guest are viewing this topic.

Kheilmann

  • Guest
Map & Disconnect Drives
« on: December 22, 2006, 03:53:13 PM »
Is it possible to map & disconnect a \\Server\Folder\ to/from a drive letter?



David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Map & Disconnect Drives
« Reply #1 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
« Last Edit: December 22, 2006, 04:37:34 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

jjs

  • Guest
Re: Map & Disconnect Drives
« Reply #2 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.