Solved

VB Script for Mapping Printers

Posted on 2006-10-20
7
270 Views
Last Modified: 2011-04-14
Hello! I am working on a VB script to use during logon to map printers. I've found everything I need except 1 line. I need to evaluate whether the current user is a member of an Active Directory security group.

For example:

IF CurrentUser is a member of "6thFloor Users"
then <DO THIS STUFF>

I have all the "Stuff" I just need the IF statement.

Thanks!
0
Comment
Question by:PaulRKrueger
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:hclgroup
ID: 17776343
0
 
LVL 4

Author Comment

by:PaulRKrueger
ID: 17776561
That looks like it would help if I actually knew this stuff. Unfortunately, I don't. From what I can see that link has information on enumerating the groups of which the user is a member. I want to ask "if the current user is a member of a specific group."
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 17776612
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Accepted Solution

by:
hclgroup earned 500 total points
ID: 17776634
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 17776664
this is the script needed to map printers using vb instaed of giving you part i rather put the whole thing


If InGroup("groupnamehere") Then
  Call AddPrinter("hcgl","servername","printername")
  objWshNetwork.setDefaultPrinter "\\servername\printername"

End If




Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\servername\printer"

WshNetwork.SetDefaultPrinter "\\servername\printer"
0
 
LVL 4

Author Comment

by:PaulRKrueger
ID: 17777368
Will give it a shot this weekend and let you know. Thanks!
0
 
LVL 4

Author Comment

by:PaulRKrueger
ID: 17790949
I had lots of trouble working with inGroup. As I looked in other places (following your link) I ended up with the script below. The functions are WAY out of my league, but it works none the less!

----------------------------------------------------------------------------

Option Explicit

Dim objADObject, strGroup, objGroupList, objSysInfo, strUser, objUser, wshNetwork

' Get the user info
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Set objADObject = GetObject(objUser.AdsPath)
Set wshNetwork = CreateObject("WScript.Network")

' Do this stuff

strGroup = "COP_Corporate"
If IsMember(strGroup) Then
      wshNetwork.AddWindowsPrinterConnection "\\tbcws121\Corp_Copier_b&W"
      wshNetwork.AddWindowsPrinterConnection "\\tbcws121\Corp_Copier_Color"
End If


' Functions

Set objGroupList = Nothing
Set objADObject =  Nothing

Function IsMember(strGroup)
' Function to test for group membership.
' strGroup is the NT name (sAMAccountName) of the group to test.
' objGroupList is a dictionary object, with global scope.
' Returns True if the user or computer is a member of the group.

  If IsEmpty(objGroupList) Then
    Call LoadGroups
  End If
  IsMember = objGroupList.Exists(strGroup)
End Function

Sub LoadGroups
' Subroutine to populate dictionary object with group memberships.
' objADObject is the user or computer object, with global scope.
' objGroupList is a dictionary object, with global scope.

  Dim arrbytGroups, j
  Dim arrstrGroupSids(), objGroup

  Set objGroupList = CreateObject("Scripting.Dictionary")
  objGroupList.CompareMode = vbTextCompare

  objADObject.GetInfoEx Array("tokenGroups"), 0
  arrbytGroups = objADObject.Get("tokenGroups")
  If TypeName(arrbytGroups) = "Byte()" Then
    ReDim arrstrGroupSids(0)
    arrstrGroupSids(0) = OctetToHexStr(arrbytGroups)
    Set objGroup = GetObject("LDAP://<SID=" & arrstrGroupSids(0) _
      & ">")
    objGroupList(objGroup.sAMAccountName) = True
    Set objGroup = Nothing
    Exit Sub
  End If
  If UBound(arrbytGroups) = -1 Then
    Exit Sub
  End If

  ReDim arrstrGroupSids(UBound(arrbytGroups))
  For j = 0 To UBound(arrbytGroups)
    arrstrGroupSids(j) = OctetToHexStr(arrbytGroups(j))
    Set objGroup = GetObject("LDAP://<SID=" & arrstrGroupSids(j) _
      & ">")
    objGroupList(objGroup.sAMAccountName) = True
  Next
  Set objGroup = Nothing

End Sub

Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (byte array) to Hex string.

  Dim k
  OctetToHexStr = ""
  For k = 1 To Lenb(arrbytOctet)
    OctetToHexStr = OctetToHexStr _
      & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
  Next
End Function

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How Complex Is This Java Course ? 9 95
countAbc challenge 9 59
topping3 challenge 14 70
I need an assist with a programming logic math question. 5 55
This article will show, step by step, how to integrate R code into a R Sweave document
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now