?
Solved

Computer Groups and Printer Scripts

Posted on 2005-03-29
10
Medium Priority
?
231 Views
Last Modified: 2010-04-18
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
Comment
Question by:MHCC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 18

Expert Comment

by:luv2smile
ID: 13653831
0
 

Author Comment

by:MHCC
ID: 13656339
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
 
LVL 15

Accepted Solution

by:
sr75 earned 1000 total points
ID: 13656893
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 15

Expert Comment

by:sr75
ID: 13656904
remove one of the "end if" from the loop!
0
 

Author Comment

by:MHCC
ID: 13657544
Thanks. I will try that and let you now!
0
 
LVL 7

Assisted Solution

by:ScrptMasta
ScrptMasta earned 1000 total points
ID: 13664281
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
 

Author Comment

by:MHCC
ID: 15618989
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question