logon.vbs脚本不映射networking驱动器

我是新来创build一个VBS脚本映射在Windows中的networking驱动器。 出于某种原因,脚本运行,但不映射任何networking驱动器时,用户login到域。 这是我正在使用的脚本。 这非常简单直接。

Option Explicit Dim wshNetwork Set wshNetwork = CreateObject("WScript.Network") wshNetwork.MapNetworkDrive "S:","\\server\shared" wshNetwork.MapNetworkDrive "U:","\\server\" & wshNetwork.UserName WScript.Quit 

我究竟做错了什么?

尝试:

 wshNetwork.MapNetworkDrive "S:","\\server\shared", True wshNetwork.MapNetworkDrive "U:","\\server\" & wshNetwork.UserName, True 

在映射驱动器之前,我还添加了一个例程来删除所有共享,以避免“设备已在使用中”错误。

 wshNetwork.RemoveNetworkDrive "S:", True, True wshNetwork.RemoveNetworkDrive "U:", True, True wscript.sleep 300 

这是我一直在使用的function:

 Function MapDrive(ByVal strDrive, ByVal strShare) ' Function to map network share to a drive letter. ' If the drive letter specified is already in use, the function ' attempts to remove the network connection. ' objFSO is the File System Object, with global scope. ' objNetwork is the Network object, with global scope. ' Returns True if drive mapped, False otherwise. Dim objDrive On Error Resume Next If (objFSO.DriveExists(strDrive) = True) Then Set objDrive = objFSO.GetDrive(strDrive) If (Err.Number <> 0) Then On Error GoTo 0 MapDrive = False Exit Function End If If (objDrive.DriveType = 3) Then objNetwork.RemoveNetworkDrive strDrive, True, True Else MapDrive = False Exit Function End If Set objDrive = Nothing End If objNetwork.MapNetworkDrive strDrive, strShare If (Err.Number = 0) Then MapDrive = True Else Err.Clear MapDrive = False End If On Error GoTo 0 End Function 

用法示例:

 If (MapDrive("Z:", "\\yourserver\yourshare") = False) Then ' Do something because there was an error. End If