+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
Scripts Thread, Print Script for one specific user in Coding and Web Development; Hi all I am in need of a bit of scripting to help solve an annoying problem.... A member of ...
  1. #1

    john's Avatar
    Join Date
    Sep 2005
    Location
    London
    Posts
    10,363
    Thank Post
    1,500
    Thanked 1,053 Times in 922 Posts
    Rep Power
    303

    Print Script for one specific user

    Hi all I am in need of a bit of scripting to help solve an annoying problem....

    A member of staff has a local printer attached to there PC, and like all other workstations has access to the central print room colour unit and some others, including a local PDF printer (for use with non-MSFT apps) and the usual MS Image writer etc...

    Now this user has issues at times with not having the local printer that is attached to the PC they are sat at as default and it choosing a network printer or another local one such as the PDF creator as the new default.

    Now most people do File > Print and check the name of the printer and manage quite well, however this user fails to do that and just does File > Print > Print before even reading what the printer is, sometimes jobs end up at the colour copier, sometimes as a PDF or sometimes to the local one and this person does handle sensitive and confidential data.

    Now you may think stupid user and I'd agree as setting default and reading from the list when you have ~4 to choose from isn't hard and the rest of my staff that have identical setup's have no issues at all doing so, but this user is very instant and says they cannot believe they are the only person in the world that "cannot" print to there own printer (aka not manage to choose it from a list).

    So I need a solution to solve this, my first idea was remove all other printer options and deny them access to network ones thus they could only use the one on the PC. This was thrown back instantly as not acceptable so is some scripting guru able to knock me up a simple script that I could put as a logon script to this users account perhaps that simple allows me to forcibly set the default printer to a named one that I choose? The printer attached is a simple HP LaserJet 1010 usb printer so nothing networkable or fancy I'm afraid and if the user logs onto a pc that isn't there own it just goes meh cannot see that and doesn't set anything?

    Any help would be appreciated, if it makes a difference the user in question uses a Windows 7 X64 PC.

    Thanks

  2. #2

    Join Date
    Jun 2010
    Location
    England
    Posts
    735
    Thank Post
    89
    Thanked 52 Times in 46 Posts
    Rep Power
    35
    You should be able to achieve all this through Group Policy Preferences.

  3. #3

    john's Avatar
    Join Date
    Sep 2005
    Location
    London
    Posts
    10,363
    Thank Post
    1,500
    Thanked 1,053 Times in 922 Posts
    Rep Power
    303
    Quote Originally Posted by ihaveaproblem View Post
    You should be able to achieve all this through Group Policy Preferences.
    GPP doesn't work reliably enough as we have tried that and it wasn't 100% reliable. The user in question needs something idiot proof and guaranteed to work.

  4. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Don't have printer on, but works between PDF/XML writers etc

    Code:
    strPrinter = "CutePDF Writer"
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
    MapPrinter = 1
    For i = 0 to oPrinters.Count - 1 Step 2
      If oPrinters.Item(i+1) = strPrinter Then
        MapPrinter = 0
        Exit For
      End If 
    Next
    If MapPrinter = 0 Then
      WshNetwork.SetDefaultPrinter strPrinter
    End If
    (Obviously change name to whatever other is showing as)

    Steve

  5. Thanks to Steve21 from:

    john (5th August 2012)

  6. #5

    john's Avatar
    Join Date
    Sep 2005
    Location
    London
    Posts
    10,363
    Thank Post
    1,500
    Thanked 1,053 Times in 922 Posts
    Rep Power
    303
    Cheers Steve will give it a test on Monday with our test account on the users PC. Assume I can just do it as the logon script in AD for that user and then they might stop complaining

  7. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Aye should work fine, just you'll need to check when it's firing off, vs your other printer settings.

    If your GPP is done after the script, it might reset defaults etc

    Steve

  8. Thanks to Steve21 from:

    john (5th August 2012)

  9. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,854
    Thank Post
    3,370
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by Steve21 View Post
    Don't have printer on, but works between PDF/XML writers etc

    Code:
    strPrinter = "CutePDF Writer"
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
    MapPrinter = 1
    For i = 0 to oPrinters.Count - 1 Step 2
      If oPrinters.Item(i+1) = strPrinter Then
        MapPrinter = 0
        Exit For
      End If 
    Next
    If MapPrinter = 0 Then
      WshNetwork.SetDefaultPrinter strPrinter
    End If
    (Obviously change name to whatever other is showing as)

    Steve
    Not that it makes much difference aside from the amount of code but just curious why are you enumerating the printers etc, couldn't you just do something like

    Code:
    strPrinter = "CutePDF Writer"
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.SetDefaultPrinter strPrinter
    The printer name needs to be exactly the same as the actual printer name when assigned to strPrinter so if it was a HP Color Laser Jet 4550c Then strPrinter would be

    strPrinter = "HP Color Laser Jet 4550c"

  10. #8

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    Not that it makes much difference aside from the amount of code but just curious why are you enumerating the printers etc, couldn't you just do something like

    Code:
    strPrinter = "CutePDF Writer"
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.SetDefaultPrinter strPrinter
    The printer name needs to be exactly the same as the actual printer name when assigned to strPrinter so if it was a HP Color Laser Jet 4550c Then strPrinter would be

    strPrinter = "HP Color Laser Jet 4550c"
    If it doesn't exist it'll still set it as default then bomb out everytime. As it'll run on computers without printer too

    Steve

  11. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,854
    Thank Post
    3,370
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Code:
    strPrinter = "CutePDF Writer" 
    Set WshNetwork = WScript.CreateObject("WScript.Network") 
    Set oPrinters = WshNetwork.EnumPrinterConnections 
    MapPrinter = 1 For i = 0 to oPrinters.Count - 1 Step 2 
      If oPrinters.Item(i+1) = strPrinter Then      
    WshNetwork.SetDefaultPrinter strPrinter     
    Exit For
       End If  
    Next
    fair enough, one last question, why use the MapPrinter as a flag when you can just set the printer as the default if it finds said printer ?

  12. #10

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    Code:
    strPrinter = "CutePDF Writer" 
    Set WshNetwork = WScript.CreateObject("WScript.Network") 
    Set oPrinters = WshNetwork.EnumPrinterConnections 
    MapPrinter = 1 For i = 0 to oPrinters.Count - 1 Step 2 
      If oPrinters.Item(i+1) = strPrinter Then      
    WshNetwork.SetDefaultPrinter strPrinter     
    Exit For
       End If  
    Next
    fair enough, one last question, why use the MapPrinter as a flag when you can just set the printer as the default if it finds said printer ?
    No particular reason, but just remember doing it your way doesn't give option for an alternative default printer/action if not found. But depends if you need to do anything else, or it's just if found do this, else nothing.

    @john Gimme a shout if it doesn't work etc.

    Steve

  13. Thanks to Steve21 from:

    mac_shinobi (6th August 2012)

  14. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,854
    Thank Post
    3,370
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Maybe a Select Case would be neater ??

    strPrinter="Printer Name"
    Select Case oPrinters.Item(i+1)
    Case strPrinter:
    WshNetwork.SetDefaultPrinter strPrinter
    Case Else:
    End Select

  15. #12

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    Maybe a Select Case would be neater ??

    strPrinter="Printer Name"
    Select Case oPrinters.Item(i+1)
    Case strPrinter:
    WshNetwork.SetDefaultPrinter strPrinter
    Case Else:
    End Select
    But that would fire off every time you loop, thus setting every printer to default no matter what it is Unless you're doing it after loop, which is no different to setting flags then.

    Steve

  16. Thanks to Steve21 from:

    mac_shinobi (6th August 2012)

  17. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,854
    Thank Post
    3,370
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Had to delete the Exit For so it will go through looping until it has finished and just tested it, so have put a msgbox "Execute" to see how many times it executes and it only does it the once

    Code:
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
    For i = 0 to oPrinters.Count - 1 Step 2
    msgbox oPrinters.Item(i+1)
    Select Case oPrinters.Item(i+1)
    Case "MP C3500 PCL5c":
    WshNetwork.SetDefaultPrinter "MP C3500 PCL5c"
    msgbox "Executed"
    Case Else:
    End Select
    Next
    Select Case would not work with variables ( at least when I have been trying it ) but I have most likely been doing it wrong.

    As @Steve21 mentioned - just stick with his code as will work better, I am just trying to see how the Select Case would work and also with variables as just doing it out of curiosity, that is all
    Last edited by mac_shinobi; 6th August 2012 at 08:58 AM.

  18. #14

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    Had to delete the Exit For so it will go through looping until it has finished and just tested it, so have put a msgbox "Execute" to see how many times it executes and it only does it the once
    What I meant is if you put something in your "case else" aka if printer doesn't exist, set this as default, It'll fire off every time the other isn't found, "on every loop"

    e.g. Printer1 isn't it, it'll fire off, Printer2 is it it'll set default, Printer3 isn't it it'll reset.

    If that made sense?

    Steve

  19. Thanks to Steve21 from:

    mac_shinobi (6th August 2012)

  20. #15

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,854
    Thank Post
    3,370
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by Steve21 View Post
    What I meant is if you put something in your "case else" aka if printer doesn't exist, set this as default, It'll fire off every time the other isn't found, "on every loop"

    e.g. Printer1 isn't it, it'll fire off, Printer2 is it it'll set default, Printer3 isn't it it'll reset.

    If that made sense?

    Steve
    That's correct - which is a shame, doh

    I take it there is no way to do error checking using the Case Else so that it doesnt repeatdly fire off the msgbox / wscript.echo commands
    Last edited by mac_shinobi; 6th August 2012 at 09:54 AM.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Want to set a profile for one specific student
    By speckytecky in forum Windows Server 2008
    Replies: 2
    Last Post: 1st September 2011, 02:55 PM
  2. one specific user profile could not load properly,
    By lionsl2005 in forum Windows Server 2008
    Replies: 1
    Last Post: 5th July 2010, 01:46 PM
  3. logon script to map specific user to share
    By techie211 in forum Scripts
    Replies: 3
    Last Post: 28th December 2009, 04:50 PM
  4. Active Directory-Script for Creating Bulk Users
    By calapso in forum How do you do....it?
    Replies: 8
    Last Post: 14th January 2009, 06:32 PM
  5. Make a script run for SINGLE domain user
    By philtomo-25 in forum How do you do....it?
    Replies: 5
    Last Post: 15th November 2007, 09:21 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
  •