Daniel Frear
Daniel Frear

Reputation: 1459

How can I display the printer properties with C#

Done quite a lot of searching around this one and so far I've only managed to get printer preferences, not properties.

I'd like to invoke the actual printer properties window, the one where you can set security data for the printer directly from code.

I've got the printer name etc, just need to be able to display it's properties

Any help would be most appreciated!

So far I've tried a few different implementations, the most common involving winspool.Drv which shows the actual printer properties window (often a custom window from the manufacturer)

Example:

Printer Properties Dialog

Upvotes: 1

Views: 4504

Answers (3)

A.Lebel
A.Lebel

Reputation: 1

To launch the printer property using the Process class and without showing the CMD window, use the following code:

string printerName = "Microsoft Print to PDF"; // Change this with your printer name 
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new 
System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C rundll32 printui.dll,PrintUIEntry /p /n \"" + printerName + "\"";
process.StartInfo = startInfo;
process.Start();

Upvotes: 0

M.Babcock
M.Babcock

Reputation: 18965

You can launch the printer properties dialog using something like

rundll32 printui.dll,PrintUIEntry /p /n "printernamegoeshere"

with the Process class.

Upvotes: 6

Yahia
Yahia

Reputation: 70379

In fact there is a native API for invoking that window - call OpenPrinter and then call PrinterProperties.

From C# you will have to go the p/invoke route...

Upvotes: 3

Related Questions