WSH Logon Script for mapping user network drive

来源:互联网 发布:神经网络理论知乎 编辑:程序博客网 时间:2024/04/30 01:34

'-----------------------------------------------------------------------
'WSH Logon Script for mapping user network drive
'-----------------------------------------------------------------------

'-----------------------------------------------------------------------
'                          Main
'Getting Each Group information of user and Call MapDRV function
'-----------------------------------------------------------------------
On Error Resume Next

Call ReNetDrive()                                                                                                                'Remove user pc all networkdrive

Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set objUser = GetObject("WinNT://" & wshNetwork.UserDomain & "/" & WshNetwork.UserName & ",user")
        For Each Group in objUser.Groups
            'WScript.Echo Group.name
            GRPName = UCase(Group.name)
            If left(GRPName,4) = "_ORG" Or left(GRPName,4) = "_FNC" Then
                WScript.Echo GRPName
                Call MapDRV(GRPName)
            End If
        Next
    Set objUser = nothing
Set WshNetwork = nothing

'Call RunWinauditu()                                                                                                            'Check hardware and software
'-------------------------------------------------------------------------------------------------------------

'-------------------------------------------------------
'Map User's NetworkDrive
'-------------------------------------------------------
Function MapDRV(GRPName)
    Set fso = CreateObject("Scripting.FileSystemObject")
        LogonPath = fso.GetParentFolderName(WScript.ScriptFullName)
        Set grplist = Fso.OpenTextFile(logonpath&"/GroupList.csv")
            Do While Not grplist.AtEndOfLine
                aGroup = Split(grplist.ReadLine,",")
                'WScript.Echo aGroup(0)
                If GRPName = aGroup(0) Then
                    WScript.Echo aGroup(0) & aGroup(1) & aGroup(2)
                    WshNetwork.MapNetworkDrive aGroup(1),aGroup(2)
                End If
            Loop
        Set grplist = Nothing
    Set fso = Nothing
End Function
'-------------------------------------------------------------------------------------------------------------

'-------------------------------------------------------
'Remove all NetworkDrive
'-------------------------------------------------------
Sub ReNetDrive()
Set WshNetwork = WScript.CreateObject("WScript.Network")
'WshNetwork.MapNetworkDrive "Z:", "//wcdc2/acc_01"
    Set oDrives = WshNetwork.EnumNetworkDrives
        For i = 0 To oDrives.Count - 1 Step 2
            If oDrives.Item(i)<>"" Then
                WScript.Echo oDrives.Item(i) &","& oDrives.Item(i+1)
                WshNetwork.RemoveNetworkDrive oDrives.Item(i), True, True
            End If
        Next
    Set oDrives = Nothing
Set WshNetwork = Nothing
end sub
'--------------------------------------------------------------------------------------------------------------

'-------------------------------------------------------
'Run a program for Check hardware and software
'-------------------------------------------------------
Sub RunWinauditu()
    Set WshNetwork = WScript.CreateObject("WScript.Network")
        Set WshShell = WScript.CreateObject("WScript.Shell")
            Call wshShell.run("//172.16.1.10/winaudit/winauditu.exe /o=html /f=//172.16.1.10/winaudit/" & wshnetwork.computername & ".html /r=so",2,True)
            Call wshShell.run("//172.16.1.10/winaudit/winauditu.exe /o=text /f=//172.16.1.10/winaudit/" & wshnetwork.computername & ".txt /r=so",2,True)
        Set WshShell = Nothing
    Set WshNetwork = nothing
End Sub
'--------------------------------------------------------------------------------------------------------------
WScript.quit

原创粉丝点击