我在使用HP LaserJet 10xx打印機從.Net 2.0打印時遇到問題。使用HP LaserJet 10xx打印.Net
偶爾(有時一個月一次,有時一天一次)打印機被阻止,以致它無法打印任何來自.net 2.0的內容。
當調用printDocument.print方法時,即使從printDialog中選擇了打印機,也會引發InvalidPrinterException。打印機處於聯機狀態並正在工作(其他所有內容都可以打印在其上),只有通過.net的打印纔會被阻止。
我發現,問題出在下面的註冊表項:
HKEY_CURRENT_USER\Printers\DevModePerUser
如果此項存在,PrintDocument.PrinterSettings.IsValid報告「假」。此鍵被擦除的時刻PrintDocument.PrinterSettings.IsValid爲'true'且打印機正在工作。現在我正在用下面的方法解決這個問題:如果打印機是「HP」而PrinterSettings是'false',那麼檢查是否存在註冊表項,擦除鍵然後執行打印。現在,我知道這是蹩腳的,但到目前爲止,我還沒有發現爲什麼會發生這種情況。我強調這隻發生在HP LaserJet 10xx打印機上。從.NET打印完全阻止,直到此註冊表項存在。
有沒有人看到這樣的錯誤,如果是的話,有什麼解決方案?
編輯:這裏是使HP1005打印機變紅的註冊表鍵。
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Printers\DevModePerUser]
"HP LaserJet P1005"=hex:48,00,50,00,20,00,4c,00,61,00,73,00,65,00,72,00,4a,00,\
65,00,74,00,20,00,50,00,31,00,30,00,30,00,35,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,04,02,01,\
dc,00,44,05,01,00,00,00,01,00,01,00,00,00,00,00,64,00,01,00,07,00,58,02,01,\
00,01,00,58,02,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,02,\
00,00,00,01,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,02,01,00,00,48,00,50,00,20,00,4c,00,61,00,73,00,65,00,72,00,4a,00,65,\
00,74,00,20,00,50,00,31,00,30,00,30,00,35,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,20,06,00,00,ac,0b,00,00,00,00,00,\
00,00,00,00,00,20,06,00,00,6c,06,00,00,00,00,00,00,12,00,00,00,ec,13,00,00,\
c8,19,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,01,00,00,00,01,00,00,00,03,00,00,00,00,00,00,00,64,00,\
00,00,01,00,00,00,0f,27,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,\
00,00,00,00,00,00,96,00,00,00,00,00,00,00,34,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,40,17,00,\
00,e2,20,00,00,ff,ff,ff,ff,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,12,00,00,00,00,00,00,00,01,00,00,00,00,00,\
00,00,01,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,\
00,02,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,01,00,00,00,\
01,00,00,00,00,00,00,00,00,00,00,00,02,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
40,17,00,00,e2,20,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,64,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,64,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,02,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,\
00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,ff,ff,ff,ff,40,17,00,00,e2,20,00,00,01,00,00,00,01,00,00,00
什麼樣的.NET程序? Windows窗體?如果您退出程序並重新開始,會發生什麼情況? – 2009-07-07 10:01:34
Windows窗體程序。退出程序不會改變任何內容。所有.NET打印都被阻塞,直到該密鑰存在。即使是最小的.NET打印示例程序也無法打印。從非.NET程序打印運行良好。 – 2009-07-07 10:24:14