Awesome, thanks for the template!!!!!!
Should I go around and disconnect the existing mapped drives?
well, I like to do it to make sure my users are all connected to the correct drives as some of them got into the habit of remapping drives. The script snippet I wrote will automagically disconnect the drive if the drive letter that you are trying to map correctly is in use.
With this setup, I will presume that I can create a different vbscript for each drive that I would like to map, would this be correct?
saving this file would be *.vbs, like in my situation it would be datadrive.vbs and specdrive.vbs, etc, etc?
funny.. madmatt asked me the same question in an IM..
basically, no - you don't create seperate scripts for each drive. The user account properties will only accept a single login script file (although, technically I suppose you could create seperate vbs files and call them through a bat file and have the bat file as your one login script.
But, generally, you'll wrap it into one file. You could remove the variables (strDriveLetter and strPath) and use the actual string values and write multiple connect lines like:
Code:
objNetwork.MapNetworkDrive "y:","\\server\share1"
objNetwork.MapNetworkDrive "z:","\\server\share2"
.
.
.
But you would have to wrap the lines to check each drive letter and disconnect the existing drive for each path if you wanted that functionality.
A better way would be to turn the mapping script section into a function/subroutine and call the function from the main script. Something along the lines of this:
Code:
MapDrive "x:","\\192.168.25.103\c$"
MapDrive "y:","\\192.168.25.103\e$"
wscript.quit
Function MapDrive(strDriveLetter,strPath)
set objNet = CreateObject("Wscript.Network")
set objFSO = CreateObject("Scripting.FileSystemObject")
if not ( objFSO.DriveExists(strDriveLetter) ) then
objNet.MapNetworkDrive strDriveLetter,strPath
else
set objDrive = objFSO.GetDrive(strDriveLetter)
if not (objDrive.ShareName = strPath) then
objNet.RemoveNetworkDrive strDriveLetter,true,true
objNet.MapNetworkDrive strDriveLetter,strPath
end if
end if
End Function
Thanks for lighting a fire under his butt, Matt, LOLOL
yeah.. I think he called me lazy or something along those lines asking why I didn't just post the script. I havea copy of the IM conversation somewhere on my work laptop (working on my home machine now).