Link to home
Start Free TrialLog in
Avatar of MHCC
MHCC

asked on

Computer Groups and Printer Scripts

I am wondering if there is any way to make like a group of computers in Active Directory so that you can reference that computer group through a VB Logon Script.  To clarify, our office has a few users that log in at completely separate areas.  For instance their main workstation is in our Business Office, but these users also log in at the Admissions department.  Now, I want to create a script that can differentiate what area the user is logging into and assign the correct network printers as the default printers.  I can't differentiate by computer name because when these users log in to the Admissions area they could be at one of 6 workstations.  

In summary, I would like to create a script that can somehow reference a group of computers in a certain location so that I can assign the correct default network printers while the user is logged in at that specific area. I would rather not have to reference each computer name individually in the script (like a number of if then else statements), which is why I was wondering if there is any way to assign certain computers to a group that can be referenced in VBScript.

Thanks,
Jason
Avatar of luv2smile
luv2smile

Avatar of MHCC

ASKER

I cannot get this script to work for me.  It keeps saying that I have an "unspecified error" on the line where the first "GetObject" appears.  It happens when I run my version of the script and the author's original version.  I do not know what is causing this as the error is "unspecified." Other than that the script seems to look all right.  If I could just figure out what is causing this error then I would be very happy.  Thanks again for any help you can give.

Jason
ASKER CERTIFIED SOLUTION
Avatar of sr75
sr75
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
remove one of the "end if" from the loop!
Avatar of MHCC

ASKER

Thanks. I will try that and let you now!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MHCC

ASKER

This is what I ended up doing:

Put all computers into respective groups through Active Directory.  Create a typical script that assigns printers to each computer group (by location).  At the end of the acript add the function below.

' Function to Test for Computer Group Membership
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

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