+ Post New Thread
Results 1 to 11 of 11
Scripts Thread, Printing Script in Coding and Web Development; I am soon to rollout a a new shared printer but want it to be applied to the user, this ...
  1. #1

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,271
    Thank Post
    13
    Thanked 235 Times in 223 Posts
    Rep Power
    69

    Printing Script

    I am soon to rollout a a new shared printer but want it to be applied to the user, this will be shared from our print server. I need a script that will check the user is a member of a group called xnlnelpct.nhs.uk\sg-print-navigo, if they are a member I want them to be mapped with \\nel-prt-01\nagivo.

    I also want the script to remove any printers but leave any that are called Adobe or another which I think is CutePDF.

    Can this be done?

    Or if it cannot be done by a security group can it be done on what OU the user is in?

    Any examples would be a help, need to start testing this soon and I am not a scripter.

    Thanks

  2. #2
    maveriick's Avatar
    Join Date
    Jun 2011
    Location
    Florida
    Posts
    27
    Thank Post
    1
    Thanked 1 Time in 1 Post
    Rep Power
    0
    I have a set of scripts that look for XXXX-YY-ZZZZ and as long as a printer is named XXXX-PB or PC-ZZZZ it will map it. We apply it at the school level of GPO. (I am at the District level here in the US and we have 100+ schools) I will gladly send them to you but since they are VBS our email will not let me So I would need to do it tonight. Let me know if you would like them.

  3. #3
    bio
    bio is offline
    bio's Avatar
    Join Date
    Apr 2008
    Location
    netherlands
    Posts
    520
    Thank Post
    16
    Thanked 130 Times in 102 Posts
    Rep Power
    38
    Something to let you start (some excerpts from our script)

    Code:
    Set objNetwork = CreateObject("WScript.Network")
    Set objAllDrives = objNetwork.EnumNetworkDrives
    Set objPrinters = objNetwork.EnumPrinterConnections
    
    strADUserName = objNetwork.UserName 
    strADComputerName = objNetwork.ComputerName
    strADDomain = objNetwork.UserDomain
    'Connect to user object in AD
    Set objADUserbind = GetObject("WinNT://" & strADDomain & "/" & strADUserName)
    
    'Remove all printers
    For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2
        If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
          objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True
        End If
    Next
    
    For Each objADGroup In objADUserbind.Groups
        Select Case UCase(objADGroup.Name)
    		Case "sg-print-navigo"
    			objNetwork.AddWindowsPrinterConnection "\\nel-prt-01\nagivo"
    			objNetwork.SetDefaultPrinter "\\nel-prt-01\nagivo"
    		End Select
    Next
    bio..

  4. #4
    Marshall_IT's Avatar
    Join Date
    Jul 2011
    Location
    Leeds
    Posts
    573
    Thank Post
    79
    Thanked 84 Times in 68 Posts
    Blog Entries
    1
    Rep Power
    22
    How are you runnign the script?
    If you are running it as a logon script pushed by GPO you can filter the GPO by security group to eliminate the need for the script to check the group.

  5. #5

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,271
    Thank Post
    13
    Thanked 235 Times in 223 Posts
    Rep Power
    69
    Cheers for the replies, I will have a look when I get time next week.

    The script is a login script at the minute it is on OU but not ever one will need access hence why adding to a security group and doing it that way.

    Will look at it when I can sit down on the network and play.

  6. #6

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,271
    Thank Post
    13
    Thanked 235 Times in 223 Posts
    Rep Power
    69
    I have managed to get this script working ok:

    Code:
    Set WshNetwork = CreateObject("WScript.Network") 
     
    WshNetwork.AddWindowsPrinterConnection "\\NEL-NAVPRT-01\Mono Printing" 
    WshNetwork.AddWindowsPrinterConnection "\\NEL-NAVPRT-01\Colour Printing"
    
    WshNetwork.SetDefaultPrinter "\\NEL-NAVPRT-01\Mono Printing"
    I cannot get it to add a printer if a computer is member of certain security group, can anyone help?

  7. #7

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,271
    Thank Post
    13
    Thanked 235 Times in 223 Posts
    Rep Power
    69
    Can anyone help on this one?

  8. #8

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,717
    Thank Post
    341
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by MatthewL View Post
    Can anyone help on this one?
    When you say a certain security group, any narrowing it down?

    Steve

  9. #9

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,271
    Thank Post
    13
    Thanked 235 Times in 223 Posts
    Rep Power
    69
    Basically I want a script that if computer object is member of i.e. PRINTER1 then map \\server\printer1, if member of PRINTER2, map \\server\printer2, if that makes sense?

  10. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,896
    Thank Post
    3,415
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369
    You could use the below scripts and just alter them slightly

    Checking Group Membership in VBScript - CyrusBuilt dot Net

    Main Code :

    Code:
    '******************************************************************** '* '* Function IsGroupMember() '* Purpose : Determines if the specified object is a member of the '*               specified group. '* Input ..: UserOrComputerDN - [String] The distinguished name of '*                               the user or computer to check. '*           GroupName        - [String] The name of the group to '*                               check membership of. '* Output .: True  - The user is a member. '*           False - The user is not a member, the group does not '*                   exist, or the user does not exist. '* '******************************************************************** Function IsGroupMember(ByVal UserOrComputerDN, ByVal GroupName)     On Error Resume Next Dim iRet     Dim objUserOrComputer     Dim objGroup     Dim sGroup     Dim colGroups     iRet = False 'Bind user or computer AD object.  Set objUserOrComputer = GetObject("LDAP://" & UserOrComputerDN)     If ((Err.Number = 0) And (IsObject(objUserOrComputer))) Then 'Get the collection of groups the object is a member of.         colGroups = objUserOrComputer.MemberOf         If (Not IsEmpty(colGroups)) Then If (TypeName(colGroups) = "String") Then 'User is a member of only one group.  Set objGroup = GetObject("LDAP://" & colGroups)                 If ((Err.Number = 0) And (IsObject(objGroup))) Then If (LCase(objGroup.CN) = LCase(GroupName)) Then                         iRet = True End If End If Else 'Object is a member of multiple groups.  'Iterate through the groups the user is a member of and see  'if any of them match the specified group.  For Each sGroup In colGroups                     Set objGroup = GetObject("LDAP://" & sGroup)                     If ((Err.Number = 0) And (IsObject(objGroup))) Then If (LCase(objGroup.CN) = LCase(GroupName)) Then                             iRet = True Exit For End If End If Next End If End If End If 'Dispose objects and return.  Set objGroup = Nothing Set objUserOrComputer = Nothing     IsGroupMember = iRet End Function
    Code to call Function to check if the computer is apart of the relevant security group(s) - in your case Printer1, Printer2 etc

    Code:
    Set WshNetwork = CreateObject("WScript.Network") 
    Dim userDN Dim Printer1, Printer2
    Printer1 = "Printer1"
    Printer2 = "Printer2" 
    userDN = "CN=John Doe,OU=My Division,DC=fabrikam,DC=com" 
    If IsGroupMember(userDN, Printer1) Then    
    WshNetwork.AddWindowsPrinterConnection "\\Server\Printer1"  
    End If
    If IsGroupMember(userDN, Printer2) Then    
    WshNetwork.AddWindowsPrinterConnection "\\Server\Printer2"  
    End If
     WshNetwork.SetDefaultPrinter "\\Server\PrinterX"
    Adjust PrinterX for Printer1 or Printer2 depending on which you want setting as default or whatever, also you need to adjust the userDN ( LDAP path ) for your computers OU
    Last edited by mac_shinobi; 22nd May 2012 at 08:36 AM.

  11. #11

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,271
    Thank Post
    13
    Thanked 235 Times in 223 Posts
    Rep Power
    69
    Thanks for that, I will give it a go later this week when I am back in the office and let you know.

SHARE:
+ Post New Thread

Similar Threads

  1. IE8 Not Printing script
    By swordfish215 in forum Scripts
    Replies: 0
    Last Post: 18th May 2011, 12:39 PM
  2. Location Aware Printing (VBS Script)
    By Fatmas in forum How do you do....it?
    Replies: 13
    Last Post: 24th January 2011, 04:13 PM
  3. Replies: 18
    Last Post: 14th October 2005, 09:28 AM
  4. Network Printing
    By ninjabeaver in forum Windows
    Replies: 26
    Last Post: 22nd August 2005, 08:28 PM
  5. FREE: Microsoft Script-O-Matic
    By zippy in forum Downloads
    Replies: 0
    Last Post: 27th July 2005, 07:26 PM

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
  •