Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System;
- var description = new scan_app;
- var param1 = null, param2 = null;
- var fso, f1, ts, ForReading, ForWriting, s, wsh, guid;
- function scan_app()
- {
- var objArgs = Environment.GetCommandLineArgs();
- // write_log(get_ini_value("config.ini", "logfile"), objArgs);
- switch (objArgs.length) //Анализируем параметры командной строки
- {
- case 3:
- param1 = objArgs(1);
- param2 = objArgs(2);
- break;
- case 2:
- if (objArgs(1) == "-reg") reg_app(objArgs(0));
- else
- if (objArgs(1) == "-unreg") unreg_app();
- else write_log(get_ini_value("config.ini", "logfile"), "Usage:\nscan.exe -reg\nscan.exe -unreg\nscan.exe param1 param2");
- return;
- default:
- write_log(get_ini_value("config.ini", "logfile"), "Usage:\nscan.exe -reg\nscan.exe -unreg\nscan.exe param1 param2");
- return;
- }
- write_log(get_ini_value("config.ini", "logfile"), "Parameters:\n" + objArgs);
- switch (param2) //Запускаем приложения при получении нужных параметров
- {
- case get_ini_value("config.ini", "scan_flag"):
- wsh = new ActiveXObject("WScript.Shell");
- wsh.Run(get_ini_value("config.ini", "scan_app"),6);
- break;
- case get_ini_value("config.ini", "print_flag"):
- wsh = new ActiveXObject("WScript.Shell");
- wsh.Run(get_ini_value("config.ini", "print_app"),6);
- break;
- case get_ini_value("config.ini", "mail_flag"):
- wsh = new ActiveXObject("WScript.Shell");
- wsh.Run(get_ini_value("config.ini", "mail_app"),6);
- break;
- default:
- write_log(get_ini_value("config.ini", "logfile"), "No valid parameters\n" + objArgs);
- }
- return;
- }
- function reg_app(scan_app_path) //Регистрируем приложение в реестре
- {
- guid = "{FC36F676-4675-4CC9-B705-3AC86F456214}";
- //Регистрируем Handler
- var Root = "HKEY_LOCAL_MACHINE";
- var key = "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\AutoplayHandlers\\Handlers\\WIA_" + guid + "\\";
- var valname = "Action";
- var valx = "AppScan";
- var WshShell = new ActiveXObject("WScript.Shell");
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "CLSID";
- valx = "WIACLSID";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "DefaultIcon";
- valx = "sti.dll,0";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "InitCmdline";
- valx = "/WiaCmd;" + scan_app_path + " /StiDevice:%1 /StiEvent:%2;";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "Provider";
- valx = "AppScan";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- //Регистрируем приложение
- key = "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\StillImage\\Registered Applications\\";
- valname = "AppScan";
- valx = scan_app_path + " /StiDevice:%1 /StiEvent:%2;";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- //Регистрируем обработчик событий от сканера
- key = "\\SYSTEM\\CurrentControlSet\\Control\\StillImage\\Events\\STIProxyEvent\\" + guid + "\\";
- valname = "Cmdline";
- valx = scan_app_path + " /StiDevice:%1 /StiEvent:%2;";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "Desc";
- valx = "Direct scan";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "Icon";
- valx = "sti.dll,0";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- valname = "Name";
- valx = "ScanApp";
- WshShell.RegWrite(Root + key + valname, valx, "REG_SZ");
- write_log(get_ini_value("config.ini", "logfile"), "Application registered. Press scan button, choose ScanApp in menu to get button event id in log file.");
- return;
- }
- function unreg_app() //Удаляем приложение из реестра
- {
- guid = "{FC36F676-4675-4CC9-B705-3AC86F456214}";
- var Root = "HKEY_LOCAL_MACHINE";
- var key = "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\AutoplayHandlers\\Handlers\\WIA_"+ guid +"\\";
- var WshShell = new ActiveXObject("WScript.Shell");
- WshShell.RegDelete(Root + key);
- key = "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\StillImage\\Registered Applications\\AppScan";
- WshShell.RegDelete(Root + key);
- key = "\\SYSTEM\\CurrentControlSet\\Control\\StillImage\\Events\\STIProxyEvent\\" + guid + "\\";
- WshShell.RegDelete(Root + key);
- write_log(get_ini_value("config.ini", "logfile"), "Application unregistered.");
- return;
- }
- function get_ini_value(iniFile, valueName) //Чтение параметра из ini файла
- {
- var app_path = AppDomain.CurrentDomain.BaseDirectory;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- ForReading = 1;
- ts = fso.OpenTextFile(app_path + iniFile, ForReading);
- while (!ts.AtEndOfStream)
- {
- s = ts.ReadLine();
- if (s.IndexOf("$date$") > 0) //Если в строке есть патерн даты
- {
- var date = new Date();
- var date_print = date.getYear() + ".";
- if (eval(date.getMonth()) < 10) date_print += "0"; date_print += date.getMonth() + ".";
- if (eval(date.getDate()) < 10) date_print += "0"; date_print += date.getDate() + " ";
- if (eval(date.getHours()) < 10) date_print += "0"; date_print += date.getHours() + "-";
- if (eval(date.getMinutes()) < 10) date_print += "0"; date_print += date.getMinutes() + "-";
- if (eval(date.getSeconds()) < 10) date_print += "0"; date_print += date.getSeconds();
- s = s.substring(0, s.IndexOf("$date$")) + date_print + s.substring(s.IndexOf("$date$") + 6, s.length);
- }
- if (s.substring(0, s.IndexOf("=")) == valueName) return s.substring(s.IndexOf("=") + 1, s.length);
- }
- ts.Close();
- return;
- }
- function write_log(logFileName, logstring) //Пишем в лог файл
- {
- if (get_ini_value("config.ini", "debugflag") == "true")
- {
- var app_path = AppDomain.CurrentDomain.BaseDirectory;
- ForWriting = 2;
- fso = new ActiveXObject("Scripting.FileSystemObject");
- ts = fso.OpenTextFile(app_path + logFileName, ForWriting, true);
- ts.WriteLine(logstring) ;
- ts.Close();
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement