VBScript mysterium - Why isn't network drives connected at logon?
This is one of the strangest things I've ever seen. I've got this logon script that basically disconnects a set of Network drives and then reconnects them. Previously, all users had a batch file set in their AD profile to run. After I wrote the vbscript, I just run that via the batch script. And it's been working just fine.
Now however, I tried to create a GPO and set the vbscript directly in there. And strangely enough, no network drives are connected. So I began poking around, puttinga msgbox right before the drives are connected. And one right after. Immediatly after login I can see the first textbox appear. After I click OK, the drives are sup开发者_JAVA技巧posed to be connected. But they don't. And right after, I can see the second text box.
What's really weird is that if I run the script manually directly after, everything works just fine! I even tried to put a sleep command on the top of the script now, just in case there's some mismatch in the replication of the domain controllers. But that didn't do anything either.
Here's the script as it is right now:
'Run the script
mapNetworkdrives
Public Sub mapNetworkdrives()
' Lag WScript.Network-objekt
Set objNetwork = CreateObject("WScript.Network")
Set objFso = CreateObject("Scripting.FileSystemObject")
'On Error Resume Next
' Fjern eksisterende nettverksdrev først
removeNetworkDrives objFSO, objnetwork
Dim userName
userName = objNetwork.UserName
Dim computerName
computerName = objNetwork.ComputerName
' Sjekk om det er Citrix som blir logget på
If computerName = "JBC" Then
If Not isDriveConnected("S", objFso, objNetwork) = True Then
objNetwork.MapNetworkDrive "S:", "\\sharepoint.ourcompany.no\prosj"
End if
End if
' Sjekk om nettverksdrev er allerede koblet opp
'objNetwork.MapNetworkDrive "Z:", "\\ourcompany.local\files\Brukere\" & username
objNetwork.MapNetworkDrive "P:", "\\ourcompany.local\files\felles"
objNetwork.MapNetworkDrive "Q:", "\\ourcompany.local\files\maler"
objNetwork.MapNetworkDrive "R:", "\\ourcompany\DIY"
objNetwork.MapNetworkDrive "N:", "\\ourcompany\felles\navn"
Set objNetwork = Nothing
Set objFSO = Nothing
End Sub
Public Sub removeNetworkDrives(ByVal objFSO, ByVal objNetwork)
'On Error Resume Next
If isDriveConnected("Z", objFSO) Then
objNetwork.RemoveNetworkDrive "Z:", True, True
End if
If isDriveConnected("P", objFSO) = True Then
objNetwork.RemoveNetworkDrive "P:", True, True
End if
If isDriveConnected("Q", objFSO) = True Then
objNetwork.RemoveNetworkDrive "Q:", True, True
End if
If isDriveConnected("R", objFSO) = True Then
objNetwork.RemoveNetworkDrive "R:", True, True
End if
If isDriveConnected("N", objFSO) = True Then
objNetwork.RemoveNetworkDrive "N:", True, True
End if
Set objNetwork = Nothing
End Sub
Can anybody see anything that I cannot? Am I missing something here? The very same script works just fine if I run the batch file first, which again runs this very same script. The only thing I can think of is that some DNS server might not be ready or something at the time the script is run.
Turns out, this is "normal behaviour" as described here: http://pcloadletter.co.uk/tag/launchapp-wsf/
It is worth trying checking the privileges of the script. I've encountered a lot of network shared mapping issues with scheduled/automatic scripts.
Personally, I use batch's "net use" and it solved many weird issues.
精彩评论