How to check Printer is connected or not to your PC by Java?

前端 未结 4 1905
野的像风
野的像风 2021-01-27 06:19

I am able to get the name of printer which I had installed previously on my PC.But now its not physically connected to my pc. How should I check it first before moving to Print(

4条回答
  •  佛祖请我去吃肉
    2021-01-27 07:15

    Another way is to use PowerShell and query:

    Get-WmiObject -Query "Select * From Win32_PnPEntity where deviceid like 'USBPRINT\\%' and caption like '%Canon%'"
    

    This way, you get result only if printer is connected.

    You can query WMI from Java with many libraries, search "WMI Java library".

提交回复
热议问题