Default printer is not returned in windows 10

 ̄綄美尐妖づ 提交于 2019-12-10 15:29:07

问题


I have updated my windows environment from 8 to 10 and found that the default printer is not being returned and a different one is returned instead.

I have turned off the "Let windows manage my default printer" setting, but still not getting the default printer.

I have the following code:

 private void testPrinter() {
    PrintService[] array = PrintServiceLookup.lookupPrintServices(null, null);
    for(PrintService ps : array){
        System.out.println(ps.getName());
    }

}

In this test, I get a list of printers as following:

  • Send to one note

  • Microsoft XPS Document Writer

  • HP printer

  • Epson Printer (which is set as my default printer in windows)

However, in the following test:

 PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
 System.out.println(ps.getName());

I get the HP printer, which is not my default printer!!! No matter which printer I chose as a default, the HP printer is returned always

I went through the java API for lookupDefaultPrintService method and it says the following:

Locates the default print service for this environment. This may return null. If multiple lookup services each specify a default, the chosen service is not precisely defined, but a platform native service, rather than an installed service, is usually returned as the default. If there is no clearly identifiable platform native default print service, the default is the first to be located in an implementation-dependent manner.

This may include making use of any preferences API that is available as part of the Java or native platform. This algorithm may be overridden by a user setting the property javax.print.defaultPrinter. A service specified must be discovered to be valid and currently available to be returned as the default.

In windows 8, there was no issue with returning the default printer. After updating I'm getting this problem. How can I solve this issue?


回答1:


As pointed out in this guide, Windows 10 reconfigure your default printer each time you print, setting the default as the last used device. You have to change this setting.

Edit: You can also try to directly disable the feature via registry (regedit.exe), searching for all LegacyDefaultPrinterMode DWORD instances and setting them to 1 (off). Usually the main instance is here:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows


来源:https://stackoverflow.com/questions/35958538/default-printer-is-not-returned-in-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!