U
Usenet
Guest
I'm hoping someone can help. I'm trying to move our logon scripts over
from a mix of batch files and kixtart to vbscript.
So far so good, except I have an issue with getting the script to map
network drives reliably.
In our environment let's say everyone has to have "r" drive mapped to
\\server\share.
Then depending which department a user is in they need a set of drives
mapping for that department.
So I have the following (not the whole script, modified to post the
relevant bits):
Dim objADSysInfo, WshShell, WshNetwork
Set objADSysInfo = CreateObject("ADSystemInfo")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
FirstSub
SecondSub
ThirdSub
Mappings
Sub Mappings
WshNetwork.RemoveNetworkDrive "r:"
WshNetwork.MapNetworkDrive "r:", "\\server\share"
strUserPath = "LDAP://" & objADSysInfo.UserName
Set objUser = GetObject(strUserPath)
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case Left(strGroupName, 4)
Case "0001"
WshNetwork.RemoveNetworkDrive "x:"
WshNetwork.RemoveNetworkDrive "y:"
WshNetwork.RemoveNetworkDrive "z:"
WshNetwork.MapNetworkDrive "x:", "\\server\share"
WshNetwork.MapNetworkDrive "y:", "\\server\share"
WshNetwork.MapNetworkDrive "z:", "\\server\share"
Case "0002", "0003", "0004", "0005"
WshNetwork.RemoveNetworkDrive "x:"
WshNetwork.MapNetworkDrive "x:", "\\server\share"
End Select
Next
End Sub
AIUI this should remove each drive (in case it's already in use for
something else) and then map each drive.
The "On Error Resume Next" is there so that the script doesn't tank if
an attempt is made to remove a non-existent mapping, or if a server or
share is down at the time someone logs on etc. so AIUI I need it in
there.
The problem I'm seeing is that let's say I don't have an "r" drive, the
script above doesn't seem to map it *if* the line is there to unmap it
first. Same for the other drives.
If I remove the line to unmap the drives, and manually disconnect them
before running the script they map.
If I remove the "On Error Resume Next" line the script tanks the first
time a drive doesn't exist to be removed etc.
I'm slightly confused and would appreciate someone casting an eye and
telling me if I've done something really stupid or could do it
differently/better to be more robust etc.
Thanks in advance.
from a mix of batch files and kixtart to vbscript.
So far so good, except I have an issue with getting the script to map
network drives reliably.
In our environment let's say everyone has to have "r" drive mapped to
\\server\share.
Then depending which department a user is in they need a set of drives
mapping for that department.
So I have the following (not the whole script, modified to post the
relevant bits):
Dim objADSysInfo, WshShell, WshNetwork
Set objADSysInfo = CreateObject("ADSystemInfo")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
FirstSub
SecondSub
ThirdSub
Mappings
Sub Mappings
WshNetwork.RemoveNetworkDrive "r:"
WshNetwork.MapNetworkDrive "r:", "\\server\share"
strUserPath = "LDAP://" & objADSysInfo.UserName
Set objUser = GetObject(strUserPath)
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case Left(strGroupName, 4)
Case "0001"
WshNetwork.RemoveNetworkDrive "x:"
WshNetwork.RemoveNetworkDrive "y:"
WshNetwork.RemoveNetworkDrive "z:"
WshNetwork.MapNetworkDrive "x:", "\\server\share"
WshNetwork.MapNetworkDrive "y:", "\\server\share"
WshNetwork.MapNetworkDrive "z:", "\\server\share"
Case "0002", "0003", "0004", "0005"
WshNetwork.RemoveNetworkDrive "x:"
WshNetwork.MapNetworkDrive "x:", "\\server\share"
End Select
Next
End Sub
AIUI this should remove each drive (in case it's already in use for
something else) and then map each drive.
The "On Error Resume Next" is there so that the script doesn't tank if
an attempt is made to remove a non-existent mapping, or if a server or
share is down at the time someone logs on etc. so AIUI I need it in
there.
The problem I'm seeing is that let's say I don't have an "r" drive, the
script above doesn't seem to map it *if* the line is there to unmap it
first. Same for the other drives.
If I remove the line to unmap the drives, and manually disconnect them
before running the script they map.
If I remove the "On Error Resume Next" line the script tanks the first
time a drive doesn't exist to be removed etc.
I'm slightly confused and would appreciate someone casting an eye and
telling me if I've done something really stupid or could do it
differently/better to be more robust etc.
Thanks in advance.