LoginSignup
2
2

More than 5 years have passed since last update.

PowerShellでプリンタートレイの数値Valueを見つける

Last updated at Posted at 2016-08-17

Accessのプリンタートレイ指定が、

  • acPRBNUpper
  • acPRBNMiddle
  • acPRBNLower
  • acPRBNAuto

では指定できないプリンターが発見。

この場合、プリンター固有のトレイの数値Valueを渡してやる必要がある。
本来はVisual Studioを引っ張り出してWindowsのAPIを見ながらテストコードを書いて調べる必要がある。
でもそんな面倒なことはしたくない。
PowerShellでサッと何とかならないものだろうか?

Get-PrintConfigurationを使って調べる

Get-PrintConfiguration
PS1 > $conf=Get-PrintConfiguration -PrinterName "SHARP MX-4140FN SPDL2-c(Color)"
PS1 > $conf.PrintCapabilitiesXML > print.xml

このXMLにトレイの番号が入っている。

PrintCapablititesから出力したprint.xmlをInternetExplorer11かEdgeで開く。
プリンタートレイの部分だけ抜粋すると下記のようになる。

JobInputBinを抜粋
<?xml version="1.0"?>
-<psf:PrintCapabilities xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords" xmlns:ns0000="http://schemas.microsoft.com/windows/printing/oemdriverpt/SHARP_MX_4140FN_SPDL2_c_5_2_3790_2_" version="1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework">
-<psf:Feature name="psk:JobInputBin">
-<psf:Property name="psf:SelectionType">
<psf:Value xsi:type="xsd:QName">psk:PickOne</psf:Value>
</psf:Property>
-<psf:Property name="psk:DisplayName">
<psf:Value xsi:type="xsd:string">給紙方法(S)</psf:Value>
</psf:Property>
-<psf:Option name="ns0000:Auto">
-<psf:Property name="psk:DisplayName">
<psf:Value xsi:type="xsd:string">自動給紙</psf:Value>
</psf:Property>
</psf:Option>
-<psf:Option name="ns0000:User0000000261">
-<psf:Property name="psk:DisplayName">
<psf:Value xsi:type="xsd:string">手差し</psf:Value>
</psf:Property>
</psf:Option>
-<psf:Option name="ns0000:User0000000257">
-<psf:Property name="psk:DisplayName">
<psf:Value xsi:type="xsd:string">トレイ 1</psf:Value>
</psf:Property>
</psf:Option>
-<psf:Option name="ns0000:User0000000258">
-<psf:Property name="psk:DisplayName">
<psf:Value xsi:type="xsd:string">トレイ 2</psf:Value>
</psf:Property>
</psf:Option>
</psf:Feature>
</psf:PrintCapabilities>

上記のXMLの分析を行うと、
トレイのValueは次のようになる。

  • トレイ1 257
  • トレイ2 258
  • 手差し 261

これをトレイの命令にセットすることにより、
トレイ指定ができるようになる。

参考文献

Get-PrintConfiguration
PaperBin - Access

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2