如何使用 WMI 获取打印机的纸张来源?
How to get a printer's paper sources using WMI?
PrinterSettings
有一个 PaperSources
属性,它是打印机可用的纸张来源(纸盒)的集合。
但是,我需要使用 WMI
获取论文来源,但我看到的只是 'PaperSizesSupported' 和 'PaperTypesAvailable' 等属性。
WMI 中的论文来源 属性 在哪里?
不幸的是,没有 WMI class 包含 OS 来提供您正在寻找的信息。在 .NET 中,PrinterSettings
class 此信息是通过对 winspool.drv
中的 DeviceCapabilities()
函数的 pinvoke 调用收集的。他们没有在任何 ROOT\cimv2
WMI classes 中提供这些功能,包括以下内容:
- CIM_Printer(这是Win32_Printer的派生)
- Win32_PerfFormattedData_Spooler_PrintQueue
- Win32_PerfRawData_Spooler_PrintQueue
- Win32_Printer
- Win32_Printer配置
- Win32_PrinterDriver
- Win32_PrintJob
- MSFT_Printer(与其他一些 classes 位于 ROOT/StandardCimv2 命名空间中)
还有其他一些打印机 class,但这些打印机 class 包含用于查询的任何数据。如果您在 .NET 中开发解决方案,我建议您只使用 System.Drawing 命名空间 (there is an answer here with a great example) 中的 PrinterSettings class。如果您使用的是脚本语言,则可以通过在 PowerShell 中使用 .NET 程序集来完成类似的工作,如下所示:
Add-Type -AssemblyName System.Drawing
$PrinterSettings = New-Object System.Drawing.Printing.PrinterSettings
ForEach ($Printer in Get-Printer) {
$PrinterSettings.PrinterName = $Printer.Name
Write-Host $Printer.Name
Write-Host $PrinterSettings.PaperSources
}
PrinterSettings
有一个 PaperSources
属性,它是打印机可用的纸张来源(纸盒)的集合。
但是,我需要使用 WMI
获取论文来源,但我看到的只是 'PaperSizesSupported' 和 'PaperTypesAvailable' 等属性。
WMI 中的论文来源 属性 在哪里?
不幸的是,没有 WMI class 包含 OS 来提供您正在寻找的信息。在 .NET 中,PrinterSettings
class 此信息是通过对 winspool.drv
中的 DeviceCapabilities()
函数的 pinvoke 调用收集的。他们没有在任何 ROOT\cimv2
WMI classes 中提供这些功能,包括以下内容:
- CIM_Printer(这是Win32_Printer的派生)
- Win32_PerfFormattedData_Spooler_PrintQueue
- Win32_PerfRawData_Spooler_PrintQueue
- Win32_Printer
- Win32_Printer配置
- Win32_PrinterDriver
- Win32_PrintJob
- MSFT_Printer(与其他一些 classes 位于 ROOT/StandardCimv2 命名空间中)
还有其他一些打印机 class,但这些打印机 class 包含用于查询的任何数据。如果您在 .NET 中开发解决方案,我建议您只使用 System.Drawing 命名空间 (there is an answer here with a great example) 中的 PrinterSettings class。如果您使用的是脚本语言,则可以通过在 PowerShell 中使用 .NET 程序集来完成类似的工作,如下所示:
Add-Type -AssemblyName System.Drawing
$PrinterSettings = New-Object System.Drawing.Printing.PrinterSettings
ForEach ($Printer in Get-Printer) {
$PrinterSettings.PrinterName = $Printer.Name
Write-Host $Printer.Name
Write-Host $PrinterSettings.PaperSources
}