Coder Social home page Coder Social logo

wia-cmd-scanner's Introduction

wia-cmd-scanner

This (very) small utility (~30 KB executable) provides an easy to use command-line interface to WIA-compatible scanners for Windows OS. If scanner is accessible using Windows Fax and Scan application, it is very likely to be compatible with this tool. Compiled binaries can be downloaded from Releases

The utility is built around WIA (Microsoft Windows Image Acquisition Library v2.0) and requires Microsoft .NET Framework 4.0 (it is likely already included in your Windows OS). The utility is portable and requires no installation. Both 32-bit and 64-bit versions of Windows XP (see the note below), Windows Vista, Windows 7, Windows 8/8.1, Windows 10 are supported.

Usage

Usage: wia-cmd-scanner [OPTIONS]...

All arguments are mandatory. Arguments must be ordered as follows:

  /w WIDTH                        width of the scan area, mm
  /h HEIGHT                       height of the scan area, mm
  /dpi RESOLUTION                 scan resolution, dots per inch
  /color {RGB,GRAY,BW}            scan color mode
  /format {BMP,PNG,GIF,JPG,TIF}   output image format
  /output FILEPATH                path to output image file

Use /w 0 and /h 0 for scanner-defined values, e.g. for receipt scanners

e.g. for A4 size black and white scan at 300 dpi:
wia-cmd-scanner /w 210 /h 297 /dpi 300 /color BW /format PNG /output .\scan.png

Build

The utility is compiled using Microsoft Visual Studio 2012 Express.

No Visual Studio project files are provided, since the code can be imported into Visual Studio project from scratch in few easy steps (shown according to Visual Studio 2012 layout):

  • File -> New Project
  • Installed -> Templates -> Visual Basic -> Windows -> Console Application
  • copy-paste code from wia-cmd-scanner.vb to Module1.vb (empty file will be opened in editor)
  • right-click on ConsoleApplication in Solution Explorer and choose Add Reference...
    • choose COM -> Type Libraries
    • search for image and select Microsoft Windows Image Acquisition Library v2.0
  • compile via BUILD -> Build Solution

Scripting and automation

You can build your own automation tools around wia-cmd-scanner.exe binary using batch/powershell. E.g. a simple batch job infinitely waiting for key press and scanning to a file with timestamp can be very simply achieved as follows:

@setlocal enabledelayedexpansion
:loop
    @echo off
    @for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
    @set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,2%
    @echo on
    wia-cmd-scanner.exe /w 215.9 /h 279.4 /dpi 300 /color RGB /format PNG /output ..\scans\scan_%ldt%.png
    pause
goto loop

For more sophisticated automated jobs, check out the source code. The project is very simple and easy to modify to fit your own needs.

Note for Windows XP users

Since Windows XP only includes legacy WIA v1.0 library, WIA v2.0 needs to be installed in order for this utility to work.

Archive with required files: wiaautsdk.zip

WIA v2.0 installation

  • Copy the wiaaut.chm and wiaaut.chi files to your Help directory (usually located at C:\Windows\Help)
  • Copy the wiaaut.dll file to your System32 directory (usually located at C:\Windows\System32)
  • From a Command Prompt in the System32 directory run the following command: RegSvr32 WIAAut.dll

wia-cmd-scanner's People

Contributors

nagimov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.