如何修复 Win32_Printer.Default 字段,以便在远程使用 WMI 时返回正确的值?

发布于 2024-09-17 18:48:43 字数 236 浏览 3 评论 0原文

Win32_Printer 类为每个打印机返回一个名为 Default 的字段(布尔值)。这在本地工作并准确返回默认打印机。然而,当使用 WMI 远程连接时,它总是返回 false。

我认为这可能取决于您执行远程 WMI 查询的用户。然而,事实并非如此(我用不同的用户尝试过,没有任何变化)。

有办法解决这个问题吗?我目前正在尝试让它在 Windows 7 客户端上运行,并且我正在从 Windows 2008 R2 连接到它

The Win32_Printer class returns a field per printer called Default (a boolean value). This works locally and accurately returns the Default printer. However when remotely connecting in with WMI, it always returns false.

I thought it could depend on the user with which you did the remote WMI query. However, that's not the case (I tried it with different users and no change).

Is there anyway to fix this? I'm currently trying to get this to work on a Windows 7 client and i'm connecting to it from a Windows 2008 R2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作妖 2024-09-24 18:48:43

我可以看到这个帖子已经很老了,但我想我应该添加我的 2 美分,即使它没有帮助,但 XP 也存在同样的问题。事实上,在 XP 下您也无法读取 Win32_CDROMDrive 内容,尽管它在 Windows 7 下已修复。

您找到 WMI 默认打印机问题的答案了吗?作为替代方案,您可以读取默认打印机,但不能从注册表中读取端口,如下所示:
hkcu\software\microsoft\windows NT\CurrentVersion\Windows\Device

它将显示类似 HP Color LaserJet CP3525 PCL6,winspool,Ne03 的内容:
修剪掉垃圾,你就得到了你需要的东西。现在您已经拥有了打印机,您可以通过 WMI 获取匹配的端口。

问候,

四眼

I can see that this thread is quite old but I thought I'd add my 2 cents worth even if though it's of no help, but this same issue is there with XP too. In fact under XP you can't read the Win32_CDROMDrive stuff either, although it's fixed under Windows 7.

Have you found an answer to the default printer issue with WMI? As an alternative you can read the default printer but not the port from the registry as in:
hkcu\software\microsoft\windows NT\CurrentVersion\Windows\Device

It'll show something like HP Color LaserJet CP3525 PCL6,winspool,Ne03:
Trim the crap and you've got what you need. Now you've got the printer you can get the matching port via WMI.

Regards,

4Eyes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文