Changing your default printer settings

vinnie881

Well-known member
Joined
Sep 3, 2006
Messages
152
Programming Experience
3-5
I need to find a way to programically change the settings of my default printer (or Any printer). Idealy I would like to do the following.

1. Show a print Dialog Box
2. Let the person select a printer and set the printer settings for that printer.
3. Pass the new printer settings to the installed printer, so next time I check that printers settings in Start>Settings>Printers, it will reflect what I changed.

Any thoughts?
 
I found a work-around.

I had yet to find a good solution to this problem until now.

There has been basically no good way to change printer settings programically in .net unless you have a Printers.printdocument object. In addition to that, theres not a class that I've seen which gives you options to every property your printer has. This makes no sense, because there are a lot of times when you do not have the printdocument. This has caused a ton of issues when developing a application that uses a api to another, and you are wanting control of its print settings.

Here's the best workaround I have found, but it still works (quite well actually)

by shelling into the dll for the printui, you can do this.

1. Take a snapshot of the printers current settings
VB.NET:
dim printername as string
printername = "MyPrinter"
'or if it's a network printer
'printername = "\\Myserver\MyPrinter"

shell(rundll32 printui.dll,PrintUIEntry /Ss /n """& pd.PrinterSettings.PrinterName & """ /a ""C:\file.dat""

'Now that you have that printers settings saved to a file, you can temporarly modify the properties of the printer you want control over.

Shell("rundll32 printui.dll,PrintUIEntry /p /n """ & PrinterName & "")

'Do what ever you want to do now, becuase you have successfully changed whatever you wanted (i.e. Duplex, PaperTray, Finishing Opions, ... Anything).



' Whenever your done with this print, restore back to the original

rundll32 printui.dll,PrintUIEntry /Sr /n """& PrinterName & """ /a ""C:\file.dat""

I can not express how long it has taken to find a workaround for this issue, that gave you COMPLETE control over all your printing needs. The only downfall with this is that you will need to write code to set the focus to the print dialog launched by the shell, becaues by default when the printerdialog pops up, it ends up in the background.

Enjoy!!
 
Back
Top