AD域环境下映射网络磁盘VBS脚本

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”

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论

您的电子邮箱地址不会被公开。