使用 System.Printing 类获取打印驱动程序信息

本文关键字:打印 驱动程序 信息 获取 System Printing 使用 | 更新日期: 2023-09-27 18:34:43

我尝试获取有关我们网络中几台打印机的信息。因为我们的服务器上不允许使用 WMI,所以我尝试获取与Win32_PrinterDriver WMI 类相同的信息,例如 ConfigFileDataFileDependentFilesDriverPath等等(充其量我可以通过WMI获得的所有属性(。

PrintServer ps = new PrintServer(serverName);
PrintQueueCollection printQueueCollection = ps.GetPrintQueues();
foreach (PrintQueue pq in printQueueCollection)
{
    foreach (DictionaryEntry prop in  pq.QueueDriver.PropertiesCollection)
    {
        // add props to Dictionary/Print out or sth else
    }
...

但是,我得到的集合pq.QueueDriver.PropertiesCollection只有Name属性。我现在已经在 119 种不同的 PrintQueue 上尝试过。

我只是得到这个名字有什么原因吗?还是我在这里使用了错误的类?

使用 System.Printing 类获取打印驱动程序信息

您可以使用操作系统提供的内置Windows VB脚本获取信息。它们的位置在这里:

C:'Windows'System32'Printing_Admin_Scripts'en-US

您可以使用本文中描述的方法调用它:在 c# 中调用 VB 脚本,然后将信息管道传输到事件处理程序,并从那里获取它。

有关内置 VB 打印脚本及其功能的更多信息,请参阅此处。