java – Windows 10中未返回默认打印机

我已将我的
Windows环境从8更新到10,并发现未返回默认打印机,而是返回另一个.

我已关闭“让Windows管理我的默认打印机”设置,但仍然没有获得默认打印机.

我有以下代码:

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

}

在此测试中,我获得了以下打印机列表:

>发送到一个便笺
> Microsoft XPS文档编写器
>惠普打印机
> Epson Printer(在Windows中设置为我的默认打印机)

但是,在以下测试中:

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

我得到惠普打印机,这不是我的默认打印机!无论我选择哪台打印机作为默认打印机,都会始终返回HP打印机

我浏览了用于lookupDefaultPrintService方法的java API,它说如下:

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.

在Windows 8中,返回默认打印机没有问题.更新后我遇到了这个问题.我该如何解决这个问题?

最佳答案 正如在
guide中所指出的,Windows 10每次打印时都会重新配置默认打印机,将默认值设置为上次使用的设备.您必须更改此设置.

编辑:您还可以尝试通过注册表(regedit.exe)直接禁用该功能,搜索所有LegacyDefaultPrinterMode DWORD实例并将其设置为1(关闭).通常主要实例在这里:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
点赞