I have the following C# code that successfully prints a file that it is provided. This is in Windows 7.
// Uses the Default settings of the Windows Environment to open the file and send to printer
// Seen: http://stackoverflow.com/a/6106155
public void printPdfHiddenProcess(string filename)
{
ProcessStartInfo info = new ProcessStartInfo();
Process p;
// Set process setting to be hidden
info.Verb = "print";
info.FileName = filename;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
// Start hidden process
p = new Process();
p.StartInfo = info;
p.Start();
// Give the process some time
p.WaitForInputIdle();
Thread.Sleep(1000);
// Close it
if (p.CloseMainWindow() == false)
{
p.Close();
}
}
However, this causes it to print to the default printer. ProcessStartInfo doesn't appear to provide specific methods I can use to pass the printer name, but I might be missing something.
How can I print to a specific printer using a hidden process?