+ Post New Thread
Results 1 to 5 of 5
Coding Thread, VBS Printer script checking PC Group membership in Coding and Web Development; Hi there, I'm using some fairly basic vbs login scripts to map my printers in (below). (I've had to resort ...
  1. #1

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,679
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    46

    VBS Printer script checking PC Group membership

    Hi there,

    I'm using some fairly basic vbs login scripts to map my printers in (below). (I've had to resort back to this becuase GPP has proved to be not as efective as I'd like).

    Is there a way to find and check a PC's Group membership as part of the script?

    Specifically I want to see if the PC is a member of a windows security group and if it is apply one setting and if it isn't a different one.

    Current script for reference
    Code:
    rem ** Next line must not be deleted ** 
    Set WshNetwork = CreateObject("WScript.Network")
    rem ** This will delete existing printers **
    On Error Resume Next
    Set oPrinters = WshNetwork.EnumPrinterConnections
             For i = 1 to oPrinters.Count - 1 Step 2
                  WshNetwork.RemovePrinterConnection oPrinters.Item(i)
             Next
    rem ** Setup new printer connection **
    WshNetwork.AddWindowsPrinterConnection "\\<server>\<Printer>"
    rem ** Setup default printer **
    WshNetwork.SetDefaultPrinter "\\<server>\<Printer>"

  2. #2

    Join Date
    Oct 2012
    Posts
    58
    Thank Post
    7
    Thanked 5 Times in 4 Posts
    Rep Power
    5
    My VBS Script for students maps printers based on the OU that the PC is located in, so they only get the printer for the particular room they in at a time.

    would this be any help?

    And my staff one applies printers based on the users membership to the security group "staff".

  3. #3

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,679
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    46
    It might help, possibly the staff one...

    Basically I need to apply all the printer mappings to all the classroom PC's however I don't want to set a default if there is a local printer. As all the PC's with local printers are members of my papercut group they are easy to find, however they are scattered throughout the OU's

  4. #4

    Join Date
    Oct 2012
    Posts
    58
    Thank Post
    7
    Thanked 5 Times in 4 Posts
    Rep Power
    5
    Code:
    'Printer vbs for logon script
    
    
    'determines the user who just logged on
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    'As soon as we tack on LDAP:// and construct an ADsPath we then bind to the user account in
    'Active Directory and report back the groups the user belongs to; this can be done simply 
    'by enumerating the values in the MemberOf attribute.
    
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    
    For Each objGroup in objUser.Groups
      strGroupName = objGroup.CN
    
    
    'Mapping of printers by group and set default printer for that group
      Select Case strGroupName
         Case "Staff"
    	objNetwork.AddWindowsPrinterConnection "\\Print-Server\Staff room-2025n"
    	objNetwork.AddWindowsPrinterConnection "\\Print-Server\Room5 - HP2600n"
    
    
    
    
    
    
    '==========Add addtional case sections for each group above================
        
      End Select
    next

  5. #5

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,679
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    46
    Cheers for that. It's worked great for staff however I've hit a slight issue.

    I can adapt it to return the PC's DN but I can't get it to return the group membership of the PC so I can perform actions if a PC is in certain groups... and suggestions?



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 1
    Last Post: 14th May 2012, 02:17 PM
  2. A Printer Script
    By Ric_ in forum Scripts
    Replies: 164
    Last Post: 1st October 2010, 11:11 AM
  3. Replies: 21
    Last Post: 11th July 2006, 08:37 PM
  4. Group Membership Woes (Need Help)
    By ICTNUT in forum Windows
    Replies: 11
    Last Post: 2nd December 2005, 04:19 PM
  5. Add printer script not workling
    By mark in forum Windows
    Replies: 6
    Last Post: 15th September 2005, 11:07 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •