rgonser
asked on
VBScript Login Script
Hey Everyone,
I have a domain that I have recently wrote VBScript login scripts to replace batch ones. The problem is people started getting this "local device name is in use" error message. If I go in and manually remove the network drives before I log off and log on, the message goes away. However the default for MapNetworkDrive is supposed to be non-persistent connections? The server OS is Server 2003. Here is a basic format of the script.
Option Explicit
Dim WshNetwork, oDrives, strUName, i
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set oDrives = WshNetwork.EnumNetworkDriv es
strUName = WshNetwork.UserName
DriveMapper "H:", "\\FileSrvG4\" & strUName & "$"
DriveMapper "F:", "\\FileSrvG4\Data",
DriveMapper "M:", "\\FileSrvG4\Images"
DriveMapper "P:", "\\FileSrvG4\Pricing"
DriveMapper "S:", "\\FileSrvG4\Sales"
Sub DriveMapper(Drive, Share)
For i = 0 to oDrives.Count -1 Step 2
if LCase(Drive) = LCase(oDrives.Item(i)) then
if not LCase(Share) = LCase(oDrives.Item(i+1)) then
WshNetwork.RemoveNetworkDr ive Drive, true, true
Else
Exit Sub
End if
End if
Next
WshNetwork.MapNetworkDrive Drive, Share
End Sub
Thank you!
I have a domain that I have recently wrote VBScript login scripts to replace batch ones. The problem is people started getting this "local device name is in use" error message. If I go in and manually remove the network drives before I log off and log on, the message goes away. However the default for MapNetworkDrive is supposed to be non-persistent connections? The server OS is Server 2003. Here is a basic format of the script.
Option Explicit
Dim WshNetwork, oDrives, strUName, i
Set WshNetwork = WScript.CreateObject("WScr
Set oDrives = WshNetwork.EnumNetworkDriv
strUName = WshNetwork.UserName
DriveMapper "H:", "\\FileSrvG4\" & strUName & "$"
DriveMapper "F:", "\\FileSrvG4\Data",
DriveMapper "M:", "\\FileSrvG4\Images"
DriveMapper "P:", "\\FileSrvG4\Pricing"
DriveMapper "S:", "\\FileSrvG4\Sales"
Sub DriveMapper(Drive, Share)
For i = 0 to oDrives.Count -1 Step 2
if LCase(Drive) = LCase(oDrives.Item(i)) then
if not LCase(Share) = LCase(oDrives.Item(i+1)) then
WshNetwork.RemoveNetworkDr
Else
Exit Sub
End if
End if
Next
WshNetwork.MapNetworkDrive
End Sub
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
We suffer from it here too, it's not all that predictable unfortunately which has always been a little odd. I suspect it's leaving something lingering in the profile which is causing it to remain persistent.
Our drive mapping routine is not too dissimilar from yours, the only difference these days is that it removes the existing mapping (even if it's the same one) and forces an update to the profile with the new mapping.
Chris
ASKER
Could you show how I'd write a Sub that does a forced removal and remaps, because we started getting the error again today?
Sure, this is ours minus the logging bits:
Sub MapDrive(strDrive, strShare)
Dim objFileSystem, objDrive, objNetwork
Set objFileSystem = CreateObject("Scripting.Fi
If objFileSystem.DriveExists(
Set objDrive = objFileSystem.GetDrive(str
If objDrive.DriveType <> 3 Then
' Fixed Drive
Exit Sub
End If
End If
Set objFileSystem = Nothing
Set objNetwork = CreateObject("WScript.Netw
On Error Resume Next
objNetwork.RemoveNetworkDr
objNetwork.MapNetworkDrive
On Error Goto 0
Set objNetwork = Nothing
End Sub
ASKER
thanks, ill see if that is more effective.
ASKER
But thank you Chris, A+, very helpful, and thanks for the quick reply!