3

I have a rather older Canon scanner Pixma MP 110. Of course, Canon does not provide any useful drivers (their site is really desperate, frustrating and useless in all means) - the only software I found is a Chinese version with question marks everywhere.

However, if I go to Devices and printers manager under Windows and right-click the scanner, I may use Windows-integrated scanning manager that is in my native language. It has somewhat limited features but is still better than a bunch of buttons full of question marks.

I searched a little and found out that the feature I talk about is called WIA.

Here is the approach, however in Czech, which may sound to you like these question marks sound to me. enter image description here

After choosing Start scanning a dialog appears. It runs under explorer.exe, so there is no change finding out what program it actually is. enter image description here

What I want is to make a desktop shortcut, that would automatically start scanning, without me clicking the "Start scanning" and "Scan".

Also, the scanner has a button to start scanning and my computer recognizes when it's pressed. When I press it, Windows asks me what application should run for the button -- however, no scanner software worked here, nor did any appear in the selection Windows gives me. I was wondering if I could hack this to run any application for that button. (that would be useful if I ever got answer for the primary question).

enter image description here

So the questions once more, if you were too lazy to read that long post:

  1. How do I make Windows automatically start scanning from installed scanner using batch script or a simple command in .lnk file?
  2. (optional) How do I assign any application to the button press of my scanner?
1

PowerShell solution

The script should work with most scanners regardless if it's a Canon, Epson or whatever as long as they are WIA compatible and support the transfer() command. The script will start scanning immediately. All options like filename, path or image format are already set via script. You just have to start the scanning process with a shortcut

  1. Save it as e.g D:\StartScan.ps1
  2. Create a new shortcut and point it to

    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "D:\StartScan.ps1"
    

StartScan.ps1

# 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

Customizations

  • Change Item("FormatID").Value = $wiaFormatJPEG to $wiaFormatPNG (or TIFF, BMP, GIF) if you need another image format
  • Change $([Environment]::GetFolderPath("Desktop"))\Scan {0}.jpg" if you need another output path. Change the extension .jpg if you previously had changed the image format

Used resources

0

This might be better served at stackoverflow. search for the tag "WIA" and there are people who have tackled automation. Expert user level.

It is trivially easy to make a vbscript to launch the dialog, but (as far as I know with my limited knowledge) (a) WIA requires a host to handle the scanned image, so anything you do will need to receive and store the image (not merely launch the dialog) and; (b) WIA dialog does not appear to have an "unattended" mode.

A resource for you: WIA Automation

And a vbs script to launch wia (make a text file named e.g. launchWia.vbs):

set oDlg = CreateObject("WIA.CommonDialog")
oDlg.ShowAcquireImage()

Can be run using a batch file:

cscript launchWia.vbs
pause

Which can be run via a shortcut.

Again, this will probably not get you anything because it does not handle the image. See the MSDN docs for samples which deal with image handling.

0

The program is Windows Fax and Scan. enter image description here

When you click on New Scan the window you posted appears: enter image description here

0

scan.vbs

Set CommonDialog = CreateObject("WIA.CommonDialog")
Set DeviceManager = CreateObject("WIA.DeviceManager")

' List all Available Devices by Name and DeviceID
' The following example shows how to list all available Deviceices by name and DeviceID. 
Dim i, n 'As Integer
n = DeviceManager.DeviceInfos.Count
WScript.Echo "Number of Deviceice found = " & n
For i = 1 to DeviceManager.DeviceInfos.Count
  WScript.Echo " Device " & i & ":" & vbTab & DeviceManager.DeviceInfos(i).Properties("Name").Value & vbTab & "(" & DeviceManager.DeviceInfos(i).DeviceID & ")"
Next

Set DevInfo = DeviceManager.DeviceInfos(1)
Set Device = DevInfo.Connect

Device.Items(1).Properties("6146").Value = 2 'colors
Device.Items(1).Properties("6147").Value = 600 'dots per inch/horizontal
Device.Items(1).Properties("6148").Value = 600 'dots per inch/vertical
Device.Items(1).Properties("6149").Value = 0 'x point where to start scan
Device.Items(1).Properties("6150").Value = 0 'y point where to start scan
Device.Items(1).Properties("6151").Value = 5100 'horizontal exent DPI x inches wide
Device.Items(1).Properties("6152").Value = 7002 'vertical extent DPI x inches tall
Device.Items(1).Properties("4104").Value = 8 'bits per pixel

'Device.Items(1).Properties("3098").Value = 1700 'page width
'Device.Items(1).Properties("3099").Value = 2196 'page height

Set img = CommonDialog.ShowTransfer(Device.Items(1), "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", true)

img.SaveFile "F:/image.bmp"

Run "C:/Windows/System32/cscript.exe" //X "F:/scan.vbs"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.