There was the following task:
realize automatic scanning when a button is pressed on the scanner. The resulting material must fall into a network folder and have a unique name. The scanner is connected to the working machine; all scanning procedures should not distract the person working at this Windows computer.
In Linux, this problem
is solved by a couple of lines of code and the wonderful utility
Sane . With Windows, things are much more complicated. The standard software of the UMAX Astra 4700 scanner didn’t allow such things to get up. Internet search did not give any results, but there were simple utilities that allowed scanning from the command line, for example,
iCopy ,
IrfanView . Unfortunately, none of them could register in a quiet way, just like a handler for pressing a scanner button and just silently scan into the right folder. Having encountered a description of how to register any application as an event handler from a scanner, I decided to write a small program in JavaScript, especially since the written script can be compiled into an executable file using the Jscript Compiler as part of the .NET Framework. A slightly buggy
iCopy was chosen as a console scanner, which does not accept some keys from the command line, which, however, is solved with a crutch - creating two copies of the program, editing settings directly in the config and launching the correct copy for each button.
Compiling the script is easy if you have the .NET Framework installed, find the jsc.exe application and run the command line:
jsc.exe /target:winexe scan.js
Get the compiled application scan.exe. The key "-reg" will register the program in the system, as a message handler from the scanner buttons, the key "-unreg" will return everything back. After logging in, you must restart Windows. The program has a configuration file in which you can match the messages received from the handler pressing a button with the desired application. For a simpler setup, there is a logging mode, so as not to look for event identifiers throughout the registry. After pressing the button on the scanner, we select our application, look into the log and see the second parameter id of the button press event, then write it into the configuration file.
')
Usage:
scan.exe -reg // register the program in the registry
scan.exe -unreg // delete program information from the registry
scan.exe param1 param2 // launch the application in accordance with param2
Configuration file (for my scanner):
- [debug]
- debugflag = true
- logfile = debug.log
- [flags]
- mail_flag = / StiEvent: {F61F8581-6105-11D6-AAF8-0050BA1ACA6F};
- scan_flag = / StiEvent: {F61F8582-6105-11D6-AAF8-0050BA1ACA6F};
- print_flag = / StiEvent: {F61F8583-6105-11D6-AAF8-0050BA1ACA6F};
- [applications]
- mail_app =
- scan_app = "C: \ Program Files \ iCopy \ iCopy.exe" /f:"\\server\scanned$date$.jpg "/ r: 150
- print_app = "C: \ Program Files \ iCopy \ iCopy.exe" / c
SourceTODO:
- Eliminate the focus loss of the active window when launching the application.
SOLVED: Run method parameter should be 6 - Get rid of the blinking console window. Who knows how, please tell me.
Solved: jsc.exe / target: winexe scan.js - Faced a problem, if on some machines I put the “use this application by default” button after selecting the application to handle the button, pressing this button again does not lead to anything, the application does not start, you have to go into the printer properties and set the “select applications.
Solved: it helped to return the startup statuses of Windows XP services to the standard one. It is critical that the Windows Imaging Acquisition service be launched automatically, not manually.
Download the archive with the program