如何修复 Win32_Printer.Default 字段,以便在远程使用 WMI 时返回正确的值?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以看到这个帖子已经很老了,但我想我应该添加我的 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