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 ...
-
4th August 2012, 08:44 PM #1 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
-
-
IDG Tech News
-
4th August 2012, 09:06 PM #2 You should be able to achieve all this through Group Policy Preferences.
-
-
5th August 2012, 04:24 PM #3 
Originally Posted by
ihaveaproblem
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.
-
-
5th August 2012, 04:39 PM #4 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
-
-
5th August 2012, 06:03 PM #5 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
-
-
5th August 2012, 06:08 PM #6 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
-
-
5th August 2012, 08:49 PM #7 
Originally Posted by
Steve21
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"
-
-
5th August 2012, 09:07 PM #8 
Originally Posted by
mac_shinobi
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
-
-
5th August 2012, 09:27 PM #9 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 ?
-
-
6th August 2012, 08:07 AM #10 
Originally Posted by
mac_shinobi
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
-
Thanks to Steve21 from:
mac_shinobi (6th August 2012)
-
6th August 2012, 08:14 AM #11 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
-
-
6th August 2012, 08:16 AM #12 
Originally Posted by
mac_shinobi
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
-
Thanks to Steve21 from:
mac_shinobi (6th August 2012)
-
6th August 2012, 08:43 AM #13 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.
-
-
6th August 2012, 09:11 AM #14 
Originally Posted by
mac_shinobi
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
-
Thanks to Steve21 from:
mac_shinobi (6th August 2012)
-
6th August 2012, 09:29 AM #15 
Originally Posted by
Steve21
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: 
Similar Threads
-
By speckytecky in forum Windows Server 2008
Replies: 2
Last Post: 1st September 2011, 02:55 PM
-
By lionsl2005 in forum Windows Server 2008
Replies: 1
Last Post: 5th July 2010, 01:46 PM
-
By techie211 in forum Scripts
Replies: 3
Last Post: 28th December 2009, 04:50 PM
-
By calapso in forum How do you do....it?
Replies: 8
Last Post: 14th January 2009, 06:32 PM
-
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
-
Forum Rules