Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#,已经能够使用隐藏进程打印,如何打印到特定打印机_C#_Windows_Printing_Process - Fatal编程技术网

C#,已经能够使用隐藏进程打印,如何打印到特定打印机

C#,已经能够使用隐藏进程打印,如何打印到特定打印机,c#,windows,printing,process,C#,Windows,Printing,Process,我有以下C#代码,可以成功打印提供的文件。这是在Windows7中 // 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) { Pr

我有以下C#代码,可以成功打印提供的文件。这是在Windows7中

    // 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();
        }
    }
但是,这会导致它打印到默认打印机。ProcessStartInfo似乎没有提供我可以用来传递打印机名称的特定方法,但我可能遗漏了一些东西


如何使用隐藏进程打印到特定打印机?

print
进入默认状态,要使用另一个进程,请使用
PrintTo
并命名它。类似于“保存”与“另存为”


更多信息:

看起来很有希望,但对我来说还不起作用。我会读那个链接,看看我能不能弄明白。我让它工作了!我必须更改info.Arguments,我直接传递打印机名称,如
info.Arguments=printerName成功了。如果你能更新你的答案,至少请注意这一点,我很乐意接受。更新的答案和你的评论
info.Verb = "PrintTo";               // was "Print"
string PrinterName = "Some Printer"; // add printer specific name here...
info.Arguments = PrinterName;