Mapping multiple printers by security group with VB

jeremy smith 41 Reputation points
2021-01-15T20:16:53.063+00:00

Hello all I have a vb script that adds multiple printers to a computer from our print server. But I've been having issues mapping each printer. Each printer needs to map to users with a specific security group so each user doesn't get a printer they arent supposed to get.

The script below works perfectly but when I add in the security group portion for each separate printer I can never get it to work.

Option Explicit
Dim WshNetwork
Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter1"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter2"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter3"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter4"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter5"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter6"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter7"
WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter8"
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,405 questions
{count} votes

1 answer

Sort by: Most helpful
  1. jeremy smith 41 Reputation points
    2021-01-15T20:50:40.46+00:00

    I was thinking maybe something like this possibly. I'm still figuring it out.

    On Error Resume Next
    
    
    Set objSysInfo = CreateObject(“ADSystemInfo”)
    Set objNetwork = CreateObject(“Wscript.Network”)
    
    strUserPath = “LDAP://” & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = “LDAP://” & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
        Select Case strGroupName
            Case “Finance Users”
                WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter1"
    
            Case “Human Resource Users” 
                WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter1"
    
            Case “Manufacturing Users”
                WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter1"
    
            Case “Shipping and Receiving Users”
                WshNetwork.AddWindowsPrinterConnection "\\testserver\testprinter1"
        End Select
    Next
    
    0 comments No comments