PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 3.67 average.

How to change default printer using c#.net?

 
 
Andrew
Guest
Posts: n/a
 
      26th Mar 2008
Hello, friends,

We need to programmatically change default printer in our c#.net 2005
application. We tried:

System.Drawing.Printing.PrinterSettings oPS = new
System.Drawing.Printing.PrinterSettings();

try
{
oPS.PrinterName = defaultPrinterName;
}
catch (System.Drawing.Printing.InvalidPrinterException ix)
{
Console.WriteLine(ix.Message);
return false;
}
finally
{
oPS = null;
}

but, no luck. The thrid party applications, say MS Word/NotePad, still use
previous default printer, not the new specified one.

Any ideas? Thanks a lot.


 
Reply With Quote
 
 
 
 
Henning Krause [MVP - Exchange]
Guest
Posts: n/a
 
      26th Mar 2008
Hello,

I don't think this is supported by managed code - but I could be wrong.

Anyway, take a look at the Win32 SetDefaultPrinter method
(http://msdn2.microsoft.com/en-us/library/ms535468(VS.85).aspx). You can
call it using P/Invoke.

Kind regards,
Henning Krause

"Andrew" <(E-Mail Removed)> wrote in message
news:86031ECC-1191-49CB-B18D-(E-Mail Removed)...
> Hello, friends,
>
> We need to programmatically change default printer in our c#.net 2005
> application. We tried:
>
> System.Drawing.Printing.PrinterSettings oPS = new
> System.Drawing.Printing.PrinterSettings();
>
> try
> {
> oPS.PrinterName = defaultPrinterName;
> }
> catch (System.Drawing.Printing.InvalidPrinterException ix)
> {
> Console.WriteLine(ix.Message);
> return false;
> }
> finally
> {
> oPS = null;
> }
>
> but, no luck. The thrid party applications, say MS Word/NotePad, still use
> previous default printer, not the new specified one.
>
> Any ideas? Thanks a lot.
>
>


 
Reply With Quote
 
 
 
 
peshave.sayali@gmail.com
Guest
Posts: n/a
 
      18th Jun 2012
Hi,
Please tell me how to set programmatically default printer to undefault?




On Thursday, 27 March 2008 00:28:01 UTC+5:30, Andrew wrote:
> Hello, friends,
>
> We need to programmatically change default printer in our c#.net 2005
> application. We tried:
>
> System.Drawing.Printing.PrinterSettings oPS = new
> System.Drawing.Printing.PrinterSettings();
>
> try
> {
> oPS.PrinterName = defaultPrinterName;
> }
> catch (System.Drawing.Printing.InvalidPrinterException ix)
> {
> Console.WriteLine(ix.Message);
> return false;
> }
> finally
> {
> oPS = null;
> }
>
> but, no luck. The thrid party applications, say MS Word/NotePad, still use
> previous default printer, not the new specified one.
>
> Any ideas? Thanks a lot.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
store default printer, change printer and then restore default printer? Dennis Pedersen Microsoft Excel Programming 0 14th Nov 2007 10:18 PM
After the default printer has been changed by code in Access 2003, the application still directs a report to the former default printer. Peanuts Microsoft Access Forms 2 26th Feb 2006 07:32 AM
After the default printer has been changed by code in Access 2003, the application still directs a report to the former default printer. i8mypnuts@yahoo.com Microsoft Access Form Coding 1 24th Feb 2006 02:24 PM
Printer Default Set For Color Printer, but B&W is default in Repor =?Utf-8?B?R2FyeQ==?= Microsoft Access Reports 0 20th May 2005 09:11 PM
Default printer isn't default printer??? Stan Brown Microsoft Access Reports 0 17th Apr 2005 10:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:40 AM.