📜 ⬆️ ⬇️

Automatic scan to a network folder by clicking the "Scan" button

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):
  1. [debug]
  2. debugflag = true
  3. logfile = debug.log
  4. [flags]
  5. mail_flag = / StiEvent: {F61F8581-6105-11D6-AAF8-0050BA1ACA6F};
  6. scan_flag = / StiEvent: {F61F8582-6105-11D6-AAF8-0050BA1ACA6F};
  7. print_flag = / StiEvent: {F61F8583-6105-11D6-AAF8-0050BA1ACA6F};
  8. [applications]
  9. mail_app =
  10. scan_app = "C: \ Program Files \ iCopy \ iCopy.exe" /f:"\\server\scanned$date$.jpg "/ r: 150
  11. print_app = "C: \ Program Files \ iCopy \ iCopy.exe" / c
Source

TODO:Download the archive with the program

Source: https://habr.com/ru/post/116362/


All Articles