Stopper ved Error, men skal forsætte
Hej,Jeg har et script som køres når brugeren logger ind, men den stopper hvis den ikke af en eller anden årsag ikke kan finde det share eller printer den skal tilføje.
Scriptet ser ud som følger:
' Tilføjer Netværksshare afhængig af Usergruppe
' Tilføjer Printer afhængig af Computergruppe
Option Explicit
Dim objNetwork, objSysShare1, strUserDN
Dim objGroupList, objUser, objFSO
Dim strComputerDN, objComputer
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSysShare1 = CreateObject("ADSystemShare1")
strUserDN = objSysShare1.userName
strComputerDN = objSysShare1.computerName
' Bind to the user and computer objects with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)
Set objComputer = GetObject("LDAP://" & strComputerDN)
''''''''''''''''''''''''''''''''''
''Networkshare ADD
''''''''''''''''''''''''''''''''''
' Map a network drive if the user is a member of the group.
' Alert the user if the drive cannot be mapped.
If IsMember(objUser, "Afd1") Then
On Error Resume Next
objNetwork.MapNetworkDrive "S:", "\\Server1\Share1"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "S:", True, True
objNetwork.MapNetworkDrive "S:", "\\Server1\Share1"
End If
On Error GoTo 0
End If
If IsMember(objUser, "Afd2") Then
On Error Resume Next
objNetwork.MapNetworkDrive "P:", "\\Server1\Share2"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "P:", True, True
objNetwork.MapNetworkDrive "P:", "\\Server1\Share2"
End If
objNetwork.MapNetworkDrive "R:", "\\Server1\Share3"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "R:", True, True
objNetwork.MapNetworkDrive "R:", "\\Server1\Share3"
End If
objNetwork.MapNetworkDrive "V:", "\\Server2\Share1"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "V:", True, True
objNetwork.MapNetworkDrive "V:", "\\Server2\Share1"
End If
On Error GoTo 0
End If
'Arkv (ALLE)
On Error Resume Next
objNetwork.MapNetworkDrive "T:", "\\Server3\Arkiv"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "T:", True, True
objNetwork.MapNetworkDrive "T:", "\\Server3\Arkiv"
End If
''''''''''''''''''''''''''''''''''
''Networkshare ADD - END
''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''
''Printer ADD
''''''''''''''''''''''''''''''''''
' Add a network printer if the computer is a member of the group.
' Make this printer the default.
objNetwork.RemovePrinterConnection "\\print\print101"
objNetwork.RemovePrinterConnection "\\print\print102"
If IsMember(objComputer, "COM_Afd1") Then
objNetwork.AddWindowsPrinterConnection "\\print\print201"
objNetwork.SetDefaultPrinter "\\print\print201"
End If
If IsMember(objComputer, "COM_Afd2") Then
objNetwork.AddWindowsPrinterConnection "\\print\print302"
objNetwork.SetDefaultPrinter "\\print\print302"
End If
''''''''''''''''''''''''''''''''''
''END - Printer ADD
''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''
''Clean up.
''''''''''''''''''''''''''''''''''
Set objNetwork = Nothing
Set objFSO = Nothing
Set objSysShare1 = Nothing
Set objGroupList = Nothing
Set objUser = Nothing
Set objComputer = Nothing
Function IsMember(objADObject, strGroup)
' Function to test for group membership.
' objGroupList is a dictionary object with global scope.
If IsEmpty(objGroupList) Then
Set objGroupList = CreateObject("Scripting.Dictionary")
End If
If Not objGroupList.Exists(objADObject.sAMAccountName & "\") Then
Call LoadGroups(objADObject, objADObject)
objGroupList(objADObject.sAMAccountName & "\") = True
End If
IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _
& strGroup)
End Function
Sub LoadGroups(objPriObject, objADSubObject)
' Recursive subroutine to populate dictionary object objGroupList.
Dim colstrGroups, objGroup, j
objGroupList.CompareMode = vbTextCompare
colstrGroups = objADSubObject.memberOf
If IsEmpty(colstrGroups) Then
Exit Sub
End If
If TypeName(colstrGroups) = "String" Then
Set objGroup = GetObject("LDAP://" & colstrGroups)
If Not objGroupList.Exists(objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName) Then
objGroupList(objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName) = True
Call LoadGroups(objPriObject, objGroup)
End If
Set objGroup = Nothing
Exit Sub
End If
For j = 0 To UBound(colstrGroups)
Set objGroup = GetObject("LDAP://" & colstrGroups(j))
If Not objGroupList.Exists(objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName) Then
objGroupList(objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName) = True
Call LoadGroups(objPriObject, objGroup)
End If
Next
Set objGroup = Nothing
End Sub
''''''''''''''''''''''''''''''''''
''Funktionen som gør at Networkshare fungerer
''''''''''''''''''''''''''''''''''
Function MapDrive(strDrive, 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) Then
Set objDrive = objFSO.GetDrive(strDrive)
If Err.Number <> 0 Then
On Error GoTo 0
MapDrive = False
Exit Function
End If
If CBool(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
Den skulle ikke gøre det, men er der nogen som kan se hvorfor den gør det alligevel ?
Fra
Leif