Portable way to determining of printer is physical or virtual

前端 未结 3 1966
故里飘歌
故里飘歌 2021-01-02 23:28

I need direct-to-printer functionality for my website, with the ability to distinguish a physical printer from a virtual printer (file).

Coupons.com has this functio

3条回答
  •  一向
    一向 (楼主)
    2021-01-02 23:57

    I know how to do it very easily on Win32. There is a structure called PRINTER_INFO_2 which has a field called pPortName. You can string compare it with the string "FILE" and get all the queues which are connected to the "FILE" port. And you can similarly add in more parsing logic for detecting other virtual printers. This structure is filled up by Windows when you call GetPrinter with the printer handle. Now the question is how to do it in .NET. I saw one way which is using marshalling. I saw some code snippets in http://vbcity.com/forums/t/66183.aspx. You can also look at C# interop using pInvoke. http://pinvoke.net/default.aspx/Structures/PRINTER_INFO_2.html

    Hope this helps.

提交回复
热议问题