Logon scripts for windows 2008 R2 with AD+DNS services

Hello
XP/VISTA/W7 clients are member of the domain. We have only that server as PDM

I am actually using basic .bat scripts but sometime the network shares are not created properly. Maybe DNS issue ?
I have seen vb scripts as well as .bat scripts.

I am looking for login scrips to
- connect to network shares
- connect to printers

1 - Which kind of (vbs/bat) scripts are the betther ? Some urls would help me
2 - Should I use GPO for the logon scrips ?

Thank you
tgunduzAsked:
Who is Participating?
 
Mike ThomasConnect With a Mentor ConsultantCommented:
Here is a script that I use, it will map printers and or drives based on group membership, which is really nice as you can apply security at the same time. If you need more printer or more drives just create more of those sections as many times as you need.



Option Explicit

Dim objNetwork, objSysInfo, strUserDN
Dim objGroupList, objUser, objFSO
Dim strComputerDN, objComputer

Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.userName
strComputerDN = objSysInfo.computerName

' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
strUserDN = Replace(strUserDN, "/", "\/")
strComputerDN = Replace(strComputerDN, "/", "\/")

' Bind to the user and computer objects with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)
Set objComputer = GetObject("LDAP://" & strComputerDN)

' 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, "Name Of Group") = True) Then
    If (MapDrive("R:", "\\Server\Share") = False) Then
        MsgBox "Unable to Map S: to Rv Live"
    End If
End If

' 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, "Name Of Group") = True) Then
    If (MapDrive("Q:", "\\Server\Share") = False) Then
        MsgBox "Unable to Map S: to Sage MMS"
    End If
End If


' Add a network printer if the computer is a member of the group.
' Make this printer the default.
If (IsMember(objUser, "Name Of Group") = True) Then
    objNetwork.AddWindowsPrinterConnection "\\Server\Printer"
    objNetwork.SetDefaultPrinter "\\Server\Printer"
End If

' Add a network printer if the computer is a member of the group.
' Make this printer the default.
If (IsMember(objUser, "Name Of Group") = True) Then
    objNetwork.AddWindowsPrinterConnection "\\Server\Printer"
    objNetwork.SetDefaultPrinter "\\Server\Printer"
End If


' Clean up.
Set objNetwork = Nothing
Set objFSO = Nothing
Set objSysInfo = Nothing
Set objGroupList = Nothing
Set objUser = Nothing
Set objComputer = Nothing

Function IsMember(ByVal objADObject, ByVal strGroup)
    ' Function to test for group membership.
    ' objGroupList is a dictionary object with global scope.

    If (IsEmpty(objGroupList) = True) Then
        Set objGroupList = CreateObject("Scripting.Dictionary")
    End If
    If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then
        Call LoadGroups(objADObject, objADObject)
        objGroupList.Add objADObject.sAMAccountName & "\", True
    End If
    IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _
        & strGroup)
End Function

Sub LoadGroups(ByVal objPriObject, ByVal objADSubObject)
    ' Recursive subroutine to populate dictionary object objGroupList.

    Dim colstrGroups, objGroup, j

    objGroupList.CompareMode = vbTextCompare
    colstrGroups = objADSubObject.memberOf
    If (IsEmpty(colstrGroups) = True) Then
        Exit Sub
    End If
    If (TypeName(colstrGroups) = "String") Then
        ' Escape any forward slash characters, "/", with the backslash
        ' escape character. All other characters that should be escaped are.
        colstrGroups = Replace(colstrGroups, "/", "\/")
        Set objGroup = GetObject("LDAP://" & colstrGroups)
        If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _
                & objGroup.sAMAccountName) = False) Then
            objGroupList.Add objPriObject.sAMAccountName & "\" _
                & objGroup.sAMAccountName, True
            Call LoadGroups(objPriObject, objGroup)
        End If
        Set objGroup = Nothing
        Exit Sub
    End If
    For j = 0 To UBound(colstrGroups)
        ' Escape any forward slash characters, "/", with the backslash
        ' escape character. All other characters that should be escaped are.
        colstrGroups(j) = Replace(colstrGroups(j), "/", "\/")
        Set objGroup = GetObject("LDAP://" & colstrGroups(j))
        If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _
                & objGroup.sAMAccountName) = False) Then
            objGroupList.Add objPriObject.sAMAccountName & "\" _
                & objGroup.sAMAccountName, True
            Call LoadGroups(objPriObject, objGroup)
        End If
    Next
    Set objGroup = Nothing
End Sub

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
0
 
tgunduzAuthor Commented:
It seems you are my saver these days :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.