简体   繁体   English

通过Powershell更改打印机纸盒设置

[英]Change printer paper tray settings via powershell

I attempted to use the WMI-Object to change the paper tray settings in powershell. 我试图使用WMI对象更改Powershell中的纸盒设置。 However I've just learned that the value i'm trying to change is read-only apprently. 但是,我刚刚了解到,我试图更改的值是只读的。 Could someone help me accomplish task via powershell or VBScript? 有人可以通过Powershell或VBScript帮助我完成任务吗?

$printers = Get-WMIObject -Class Win32_PrinterConfiguration | Where-Object {$_.Name -EQ "CHK.Checks"}
$printers.MediaType = 270
$printers.Put()

I attempted this and it did not work. 我尝试了这个,但是没有用。

Please help! 请帮忙!

Thanks in advance! 提前致谢!

Since the value is read-only you won't be able to use WMI to set that. 由于该值是只读的,因此您将无法使用WMI进行设置。 .Net has the System.Printing has an input bin setting, which isn't perfect but works. .Net具有System.Printing具有输入bin设置,该设置不是完美的,但可以使用。 I've made a function around this in my PSPrintTools module. 我在PSPrintTools模块中对此做了一个功能。 I think Tray1, Tray2 work as values as well, but I don't remember off the top of my head. 我认为Tray1,Tray2也可以作为值,但是我不记得我的想法了。 Outside of this then you get into editing the PrintTicket XML. 除此之外,您还可以编辑PrintTicket XML。 Here's the relevant code for just that feature: 这是该功能的相关代码:

$Printer = "Example Printer Name"
$InputBin = "AutoSelect","AutoSheetFeeder","Cassette","Manual","Tractor" #choose one
Add-Type -AssemblyName System.Printing
$Permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer
$QueuePerms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter
$PrintServer = new-object System.Printing.LocalPrintServer -ArgumentList $Permissions
$NewQueue = New-Object System.Printing.PrintQueue -ArgumentList $PrintServer,$Printer,1,$QueuePerms
$InputBinCaps = $NewQueue.GetPrintCapabilities().InputBinCapability
if ($null -ne $InputBinCaps) {
    if ($InputBinCaps.Contains([System.Printing.InputBin]::$InputBin)) {
        $NewQueue.DefaultPrintTicket.InputBin = [System.Printing.InputBin]::$InputBin
        $NewQueue.UserPrintTicket.InputBin = [System.Printing.InputBin]::$InputBin
    } else {
        Write-Error "$InputBin unavailable on $Printer"
    }
}
$NewQueue.commit()
$NewQueue.dispose()
$PrintServer.commit()
$PrintServer.dispose()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM