共计 1673 个字符,预计需要花费 5 分钟才能阅读完成。
AD 域环境下映射网络磁盘 VBS 脚本
On Error Resume Next
Dim objSysInfo
Dim objNetwork
Dim ObjFSO
Dim oShell
WScript.Sleep 5000
Set objSysInfo = Wscript.CreateObject(“ADSystemInfo”)
Set objNetwork = Wscript.CreateObject(“Wscript.Network”)
Set oShell = Wscript.CreateObject(“Shell.Application”)
Set ObjFSO = Wscript.CreateObject(“Scripting.FileSystemObject”)
strUserPath = “LDAP://” & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
For Each strGroup in objUser.MemberOf
strGroupPath = “LDAP://” & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case strGroupName
‘ 判断用户所属组
Case “FIN_ALL”
‘ 判断盘符是否存在,若存在则断开
If(ObjFSO.DriveExists(“S:”))then
objNetwork.RemoveNetworkDrive”S:”,true
End If
WScript.Sleep 1000
‘ 添加网络磁盘
objNetwork.MapNetworkDrive “S:”, “contosofsdepartmentfin”
WScript.Sleep 1000
‘ 更名网络磁盘
oShell.NameSpace(“S:”).Self.Name = “Department”
Case “GM_ALL”
If(ObjFSO.DriveExists(“S:”))then
objNetwork.RemoveNetworkDrive”S:”,true
End If
WScript.Sleep 1000
objNetwork.MapNetworkDrive “S:”, “contosofsdepartmentceo”
WScript.Sleep 1000
oShell.NameSpace(“S:”).Self.Name = “Department”
Case “IT_ALL”
If(ObjFSO.DriveExists(“S:”))then
objNetwork.RemoveNetworkDrive”S:”,true
End If
WScript.Sleep 1000
objNetwork.MapNetworkDrive “S:”, “contosofsdepartmentIS&T”
WScript.Sleep 1000
oShell.NameSpace(“S:”).Self.Name = “Department”
End Select
‘ 添加通用磁盘
Next
‘ 判断盘符是否存在,若存在则断开
If(ObjFSO.DriveExists(“X:”))then
objNetwork.RemoveNetworkDrive”X:”,true
End If
WScript.Sleep 1000
objNetwork.MapNetworkDrive “X:”, “contosofstransfer”
WScript.Sleep 1000
oShell.NameSpace(“X:”).Self.Name = “Transfer”