如何使用c#命令安装/添加虚拟打印机?

问题描述 投票:0回答:1

我正在尝试使用Windows桌面应用程序安装虚拟打印机(适用于所有版本的Windows)。我希望打印机在打印对话框的下拉列表中可用(特别是从Office)。

我正在尝试使用此代码:

public static void installPrinter(string printerName)
{
    string arg;

    arg = "printui.dll , PrintUIEntry /if /b " + "\"" + printerName + "\"" + @" /f C:\Windows\inf\ntprint.inf /r " + "\"" + "lpt1:" + "\"" + " /m " + "\"" + "Brother DCP-116C" + "\""; //initial args
    ProcessStartInfo p = new ProcessStartInfo();
    p.FileName = "rundll32.exe";
    p.Arguments = arg;
    p.WindowStyle = ProcessWindowStyle.Hidden;

    try
    {
        Process.Start(p);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.InnerException.ToString());
    }
}

但它不起作用。有什么建议?

c# .net printers
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.