【问题标题】:Change WIA scanner source in powershell script在 powershell 脚本中更改 WIA 扫描仪源
【发布时间】:2018-09-17 05:16:44
【问题描述】:

所以我使用脚本来自动扫描,一切都很好,除了我的扫描仪总是使用平板进行扫描,而且我似乎无法将来源更改为 Feeder。这是我正在使用的代码

# Create object to access the scanner

$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
# Create object to access the scanned image later
$imageProcess = new-object -ComObject WIA.ImageProcess

# Store file format GUID strings
$wiaFormatBMP  = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatPNG  = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatGIF  = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatTIFF = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"

# Scan the image from scanner as BMP
foreach ($item in $device.Items) {
    $image = $item.Transfer() 
}

# set type to JPEG and quality/compression level
$imageProcess.Filters.Add($imageProcess.FilterInfos.Item("Convert").FilterID)
$imageProcess.Filters.Item(1).Properties.Item("FormatID").Value = $wiaFormatJPEG
$imageProcess.Filters.Item(1).Properties.Item("Quality").Value = 5
$image = $imageProcess.Apply($image)

# Build filepath from desktop path and filename 'Scan 0'
$filename = "$([Environment]::GetFolderPath("Desktop"))\Scan {0}.jpg"

# If a file named 'Scan 0' already exists, increment the index as long as needed
$index = 0
while (test-path ($filename -f $index)) {[void](++$index)}
$filename = $filename -f $index

# Save image to 'C:\Users\<username>\Desktop\Scan {x}'
$image.SaveFile($filename)

# Show image 
& $filename

我只需要更改扫描仪来源,然后保存所有图像。

【问题讨论】:

  • 你在哪里分配给$device,你怎么知道你已经选择了预期的设备?
  • 其实我没有。但它似乎选择了预期的扫描仪。只有扫描仪的来源是平板,我需要将其更改为 Feeder

标签: powershell wia


【解决方案1】:

所以经过大量的研究和实验。我终于成功了。

foreach($prop in $device.Properties){
    if( $prop.Name -eq "Document Handling Select"){
        $prop.Value=1
    }
} 

但这仍然只给了我一张图片,所以我不得不对我之前给出的所有代码使用一个 while 循环。现在完美运行!

【讨论】:

    猜你喜欢
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 2014-11-12
    相关资源
    最近更新 更多