|
Question : Removing Map drives if exist before creating them using scripts.
|
|
I found this script which allows me to create a map drive when the user starts up his computer. Seems to map okay but, If we shutdown and try booting up again the computer still thinks the drive is connected. The drive letter show up in my computers with red x. I can click on it and it is still mapped to the location. Does someone add to my script or have a better one. I would like it to be able to remove the drive if its already mapped to something and then remap it to what I want mapped. I need complete and exact code to do this. I am not a script writer, very new at this. I would like to be able to cut and paste into script file with very minimal changes. Heres what pulled from the internet.
Option Explicit Dim objNetwork Dim strDriveLetter, strRemotePath strDriveLetter = "u:" strRemotePath = "\\servername\ ' Purpose of script to create a network object. (objNetwork) ' Then to apply the MapNetworkDrive method. Result u: drive Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath WScript.Quit
' End of Example VBScript.
|
|
Answer : Removing Map drives if exist before creating them using scripts.
|
|
Have a look at this script for some pointers. He's doing something similar but is checking for the drive being mapped first. If it's mapped he unmaps it and then remaps it again. ==== ' VBScript to map two printers from two servers ' Guy Thomas February 2004. ' ****************************** Option Explicit
Dim objShell, objNetwork Dim DriveLetter1, DriveLetter2, RemotePath1, RemotePath2 Dim AllDrives, AlreadyConnected, Network1, Network2, i
Set Network1 = CreateObject("WScript.Network") DriveLetter1 = "S:" ' This letter must be in CAPITALS. RemotePath1 = "\\alan\drivers"
Set objShell = CreateObject("WScript.Shell") Set objNetwork = CreateObject("WScript.Network") Set AllDrives = objNetwork.EnumNetworkDrive()
AlreadyConnected = False For i = 0 To AllDrives.Count - 1 Step 2 If AllDrives.Item(i) = DriveLetter1 Then AlreadyConnected = True Next
If AlreadyConnected = True then objNetwork.RemoveNetworkDrive DriveLetter1 objShell.PopUp "Drive " & DriveLetter1 & " disconnected."
Else
objShell.PopUp "Drive " & DriveLetter1 & " no initial connection"
End if
objNetwork.MapNetworkDrive DriveLetter1, RemotePath1 objShell.PopUp "Drive " & DriveLetter1 & " connected successfully."
WScript.Quit ' End of Script
|
|
|
|