我正在尝试使用System.printing
命名空间连接连接 C# 和远程服务器这是我的代码,它执行得很好,但它不打印任何东西,我不知道为什么。
[DllImport("winspool.drv")]
public static extern bool AddPrinterConnection(string PrinterName);
[DllImport("winspool.drv")]
public static extern bool SetDefaultPrinter(string printerName);
private void ConnectToNetworkPrinter()
{
bool result = AddPrinterConnection(@"\\CHSADMIN-PC\Canon LBP2900");
bool resultdef = SetDefaultPrinter(@"\\CHSADMIN-PC\Canon LBP2900");
}
public void Button1_Click(object sender, EventArgs e)
{
PrintServer myPrintServer = new PrintServer(
@"\\CHSADMIN-PC",
System.Printing.PrintSystemDesiredAccess.EnumerateServer);
PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
String printQueueNames = "My Print Queues:\n\n";
foreach (PrintQueue pq in myPrintQueues)
{
printQueueNames += "\t" + pq.Name + "\n";
}
Console.WriteLine(printQueueNames);
Console.WriteLine("\nPress Return to continue.");
Console.ReadLine();
}