Discussion:
How to change default printer using c#.net?
(too old to reply)
Andrew
2008-03-26 18:58:01 UTC
Permalink
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.
Henning Krause [MVP - Exchange]
2008-03-26 21:28:03 UTC
Permalink
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
Post by Andrew
Hello, friends,
We need to programmatically change default printer in our c#.net 2005
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.
p***@gmail.com
2012-06-18 07:46:31 UTC
Permalink
Hi,
Please tell me how to set programmatically default printer to undefault?
Post by Andrew
Hello, friends,
We need to programmatically change default printer in our c#.net 2005
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.
Loading...