2013-11-29 133 views
3

正在嘗試在共享打印機上打印文檔;我需要讓我的0.But默認打印機配置爲「的HP LaserJet P1505n」打印隊列details.The下面的代碼總是會從「Microsoft XPS文檔」隊列爲數字作業=的獲取共享打印機的打印隊列詳細信息

LocalPrintServer server = new LocalPrintServer() 
PrintQueueCollection queueCollection = server.GetPrintQueues(); 
PrintQueue printQueue = null; 
foreach (PrintQueue pq in queueCollection) 
{ 
Logger.LogInfo("PrintQueue1", "Printer1 Queue Name " + pq.FullName); 
printQueue = pq; 
numberOfJobs = printQueue.NumberOfJobs; 
Logger.LogInfo("numberOfJobs1"+ numberOfJobs); 
} 

如何獲得打印從該特定共享打印機排隊詳細信息?我嘗試也

PrintServer server = new PrintServer(@"\\192.168.100.168\HP LaserJet P1505n"); 

以下,但得到的錯誤爲:

Win32 error: The filename, directory name, or volume label syntax is incorrect

我失去的是什麼?

+2

您必須使用打印服務器,而不是LocalPrintServer。並使用服務器名稱,而不是打印機名稱,而不是IP地址。並有足夠的訪問權限。詢問你的局域網管理員來幫助你。 –

回答

3

How to get print queue details from that specific shared printer?

嘗試是這樣的:

// string.Empty or null for local printers 
string printServerName = @"\\server"; 
string printerName = "printer"; 

PrintServer ps = string.IsNullOrEmpty(printServerName) 
    // for local printers 
    ? new PrintServer() 
    // for shared printers 
    : new PrintServer(printServerName); 
PrintQueue pq = ps.GetPrintQueue(printerName); 

Console.WriteLine(pq.FullName); 
Console.WriteLine(pq.NumberOfJobs); 
// output is printer uri (\\server\printer) and 0. 

也可以使用服務器的IP地址(如字符串),而不是服務器名稱。

string printServerName = @"\\192.168.1.111"; // for example 


本地打印機的PDFCreator設置

string printServerName = null; 
string printerName = "PDFCreator"; 

和共享打印機P於服務器裝置S設置

string printServerName = @"\\S"; 
string printerName = "P";