net use z: \\server1\shareMe
set objNet = CreateObject("wscript.Network")
objNet.MapNetworkDrive "z:","\\server1\shareMe"
set objNet = CreateObject("Wscript.Network")
set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = "\\server1\shareName"
strDriveLetter = "z:"
'checks to see if the drive letter is already mapped
if not ( objFSO.DriveExists(strDriveLetter) ) then
'drive is not mapped, so just map the drive and we're done
objNet.MapNetworkDrive strDriveLetter,strPath
else
'if the drive is already mapped, check to see if it is mapped to the correct share
'if the drive is mapped correctly, nothing to do
'if the drive is mapped to a different share, disconnect the share and map correctly
set objDrive = objFSO.GetDrive(strDriveLetter)
if not (objDrive.ShareName = strPath) then
objNet.RemoveNetworkDrive strDriveLetter,true,true
objNet.MapNetworkDrive strDriveLetter,strPath
end if
end if
Just making sure you fulfill your duties as a moderator and master scripter. =)
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.Awesome, thanks for the template!!!!!!
Should I go around and disconnect the existing mapped drives?
funny.. madmatt asked me the same question in an IM..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?
objNetwork.MapNetworkDrive "y:","\\server\share1"
objNetwork.MapNetworkDrive "z:","\\server\share2"
.
.
.
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
MapDrive "M:","\\server\D:\Data$"
MapDrive "N:","\\server\D:\Spec$"
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
no worriesThanks again, for your input and time.
Make sure you remember to add the script to the user account so they actually run the script when they login.I am going to be making the mods to the SBS2003 Domain Controller in the morning, and I am certainly going to use that last one you posted.
Code:MapDrive "M:","\\server\D:\Data$" MapDrive "N:","\\server\D:\Spec$" wscript.quit [/quote] I'm not sure if \\server\d:\data$ is a valid share name.. you may want to test that before hand and make sure you are using the correct share path. [quote]I won't bother with going around and disconnecting the M: mapped drives already there. [/quote] As I mentioned, the script code I wrote will check and disconnect an M: drive already if it is not mapped to the correct share. The script it self will do it so you don't have to do it yourself physically. :)
logonscript.bat; mappeddrive.vbs
So regardless, Matt's pr0n will always be mapped to M?
How would you go about addressing login scripts that don't seem to run when the person is working from home? Obviously they don't hit the PDC when logging into their machines using cached credentials, and after connecting to the VPN can only access drives that were mapped from a previous session.
MapDrive "M:","\\1600SC\ClientData"