rturney
asked on
How to get printer driver name and port in C#
I am converting a large program from VB6 to C#. One of the problems I've run into is the VB6 program uses the old Kodak Imaging Control. I've not been able to find anything inexpensive to replace it with so I have got it running in the C# program. The problem is that the print method for the Kodak image control requires the printer name, driver and port. This was not much of a problem in VB6 and I used:
Private Sub cboPrinters_Click()
With frmEView
Set Printer = Printers(cboPrinters.ListI ndex)
.gstrPrnName = Printer.DeviceName
.gstrPrnDriver = Printer.DriverName
.gstrPrnPort = Printer.Port
End With
End Sub
This used the Printers collection in VB6. Does anyone know what needs to be done in C# to reveal the printer info. Most of the printers are network printers and usually one local one.
Thanks,
-Bob
Private Sub cboPrinters_Click()
With frmEView
Set Printer = Printers(cboPrinters.ListI
.gstrPrnName = Printer.DeviceName
.gstrPrnDriver = Printer.DriverName
.gstrPrnPort = Printer.Port
End With
End Sub
This used the Printers collection in VB6. Does anyone know what needs to be done in C# to reveal the printer info. Most of the printers are network printers and usually one local one.
Thanks,
-Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much for the detailed response. It appears that this will do what I need. I'll test it in my code and reply back asap.
-Bob
-Bob
BTW, that is only a subset of the full properties defined for the Win32_Printer class. Plus, I missed the comments at the top:
// Add a reference to System.Management.dll to the project.
//
// MSDN reference:
// http://msdn2.microsoft.com/en-us/library/aa394363(VS.85).aspx
Bob
// Add a reference to System.Management.dll to the project.
//
// MSDN reference:
// http://msdn2.microsoft.com/en-us/library/aa394363(VS.85).aspx
Bob
ASKER
Yippeee! Your solution was just what I needed! And the detail you provided made my job very easy.
Thanks,
-Bob
Thanks,
-Bob
ASKER
Thank you very much for the fantastic response to my problem! I am very grateful!
Best regards,
-Bob
Best regards,
-Bob
Thanks TheLearnedOne: for your posting, you just saved my head from being banged against the wall!
Just one thing though, can you think of a reason why the printer status on all my installed printrs are showing a PrinterStatus='Unknown' but when viewed in control panel | printers show as Offline or Ready?
Just one thing though, can you think of a reason why the printer status on all my installed printrs are showing a PrinterStatus='Unknown' but when viewed in control panel | printers show as Offline or Ready?
Open in new window