Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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
0
MHCC
Asked:
MHCC
2 Solutions
 
luv2smileCommented:
0
 
MHCCAuthor Commented:
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
0
 
sr75Commented:
Try this one(just remember that if you have more printers and groups to match them up when you add them into their respective arrays.  Also you need increment the Do Until line for printer/group you add):

On Error Resume Next

Grp = array("printergroup0", _
          "printergroup1", _
            "printergroup2", _
            "printergroup3")

Prt = array("\\server\printer0", _
            "\\server\printer1", _
            "\\server\printer2", _
            "\\server\printer3")

strComputer = "."

DelPrinters(strComputer)
Notebook(strComputer)

set net = CreateObject("Wscript.Network")
set ADSysInfo = Createobject("ADSystemInfo")
set strComputer = GetObject("LDAP://" & ADSysInfo.ComputerName)
strgroup = LCase(strComputer.MemberOF)

i = 0

Do until i = 4
      if InStr(strGroup, Grp(i)) then
            net.AddWindowsPrinterConnection Prt(i)
            net.SetDefaultPrinter Prt(i)
            end if
      end if
      i = i + 1
loop
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sr75Commented:
remove one of the "end if" from the loop!
0
 
MHCCAuthor Commented:
Thanks. I will try that and let you now!
0
 
ScrptMastaCommented:
Why not create seperate location OU's in the directory and move the computer objects into their respective location OU. Then you can link a specific login script to each ou based on its location.

Done.
0
 
MHCCAuthor Commented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now