Bianchi928
asked on
Mapped network drives
I have this little script that maps network drives for me. I need to change it to also do the following. If any network drive in the 'arrpath' has already been mapped previously then don't map it again. I don't want to finish up having network drives mapped twice.
Thanks
Cheers
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
arrDrives = Array("G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:", "P:" ,"Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:")
arrPath = Array("transfer" , "admin" , "econtracts" , "hrteam" , "pmp$")
For each strpath in arrpath
For Each strDrive In arrDrives
If (objFSO.DriveExists(strDri ve) = False) Then
strAvailable = strDrive
Exit For
End If
Next
Set objNetwork = CreateObject("WScript.Netw ork")
strHomeServer = "\\tyrenet-14\" & strpath
objNetwork.MapNetworkDrive strAvailable, strHomeServer, True
Wscript.Echo "Mapped Drive " & strAvailable & " to " & strHomeServer
Next
Thanks
Cheers
Set objFSO = CreateObject("Scripting.Fi
arrDrives = Array("G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:", "P:" ,"Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:")
arrPath = Array("transfer" , "admin" , "econtracts" , "hrteam" , "pmp$")
For each strpath in arrpath
For Each strDrive In arrDrives
If (objFSO.DriveExists(strDri
strAvailable = strDrive
Exit For
End If
Next
Set objNetwork = CreateObject("WScript.Netw
strHomeServer = "\\tyrenet-14\" & strpath
objNetwork.MapNetworkDrive
Wscript.Echo "Mapped Drive " & strAvailable & " to " & strHomeServer
Next
ASKER
We always reference mapped network drive by the name not the letter assigned to it. So I don't care. I just don't want to see double or triple mapped network drives
I don't know how you're using the mapped drives .. so perhaps this is of little use. Nonetheless, is there any concern about number of connections? If so, here's a way that I use "normal user behavior" to limit the number of connections:
Instead of mapping a drive, create a shortcut on the desktop pointing to the most often used folder. Then, when file access on the drive is needed, just open using the shortcut.
Most people will close the window when they're done - and this removes a connection.
In the right situations, this has very little downside. Only you would know if this helps.
Instead of mapping a drive, create a shortcut on the desktop pointing to the most often used folder. Then, when file access on the drive is needed, just open using the shortcut.
Most people will close the window when they're done - and this removes a connection.
In the right situations, this has very little downside. Only you would know if this helps.
ASKER
No, I don't want to do that. We have different mapped drives for different users and they are all persistent connections. The modification I need in my script is to check if the name in 'arrpath' is not already mapped before mapping it again.
Thanks
Cheers
Thanks
Cheers
What I generally do is to unmap the drive and remap it with one script. Seems like this accomplishes the same thing. The downside is if there are potentially active users when the script runs. So your way is better in that regard.
Hi, see how this code goes.
Regards,
Rob.
Regards,
Rob.
strServer = "\\tyrenet-14\"
arrDrives = Array("G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:", "P:" ,"Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:")
arrPath = Array("transfer" , "admin" , "econtracts" , "hrteam" , "pmp$")
Set objNetwork = CreateObject("WScript.Network")
Set objExistingDrives = objNetwork.EnumNetworkDrives
Set dctExistingDrives = CreateObject("Scripting.Dictionary")
dctExistingDrives.CompareMode = vbTextCompare
For intDrive = 0 To objExistingDrives.Count - 1 Step 2
strCurrentShare = Replace(LCase(objExistingDrives(intDrive + 1)), LCase(strServer), "")
If dctExistingDrives.Exists(strCurrentShare) = False Then dctExistingDrives.Add strCurrentShare, objExistingDrives(intDrive)
Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
For each strpath in arrpath
If dctExistingDrives.Exists(strPath) = False Then
For Each strDrive In arrDrives
If (objFSO.DriveExists(strDrive) = False) Then
strAvailable = strDrive
Exit For
End If
Next
Set objNetwork = CreateObject("WScript.Network")
strHomeServer = strServer & strpath
objNetwork.MapNetworkDrive strAvailable, strHomeServer, True
Wscript.Echo "Mapped Drive " & strAvailable & " to " & strHomeServer
Else
WScript.Echo strServer & strPath & " is already mapped to " & dctExistingDrives(strPath)
End If
Next
ASKER
Hi Rob,
Thanks for the reply. I ran the script.
Your script shows me a list of mapped drives. (as per attahed). One good things is that it didn't mapped 'transfer' again, but didn't map the others from the 'arrpath'
Cheers
output.bmp
Thanks for the reply. I ran the script.
Your script shows me a list of mapped drives. (as per attahed). One good things is that it didn't mapped 'transfer' again, but didn't map the others from the 'arrpath'
Cheers
output.bmp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Saviour. You're the man. Thanks. Cheers
No problem. Thanks for the grade.
Just to let you know, it uses objNetwork.EnumNetworkDriv es to enumerate the currently connected network drives, that gives you the drive letter and share path of each, as objExistingDrives(intDrive ) and objExistingDrives(intDrive + 1) respectively. This is why you have to use Step 2 through the array.
That's how we check the existing connections, and avoid them is one matchs the arrPaths values.
Rob.
Just to let you know, it uses objNetwork.EnumNetworkDriv
That's how we check the existing connections, and avoid them is one matchs the arrPaths values.
Rob.
ASKER
Thanks for the clarification..I didn't know that objExistingDrives(intDrive + 1) will return me the path.
Thanks
Thanks
There's a good article here on that:
http://blogs.technet.com/b/heyscriptingguy/archive/2005/09/15/how-can-i-use-a-logon-script-to-remove-all-mapped-drives.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2005/09/15/how-can-i-use-a-logon-script-to-remove-all-mapped-drives.aspx
~bp