ViciousXUSMC

Irfanview Right Click Context Menu Batch Processing

6 posts in this topic

This is a script I put together to make it as fast and as easy as possible for a user to batch process image files using the free program Irfanview.

The program itself is already really great with a batch processing feature, but it also has CMD interfacing so that just screamed "Do an Autoit Script!" at me.

 

I ended up going for context menu integration so that I could have any folder auto populate its path to the script rather than relying on the user to type it or something.

There could be some better/smarter ways to do this, but this way is working for me.

It consists of two scripts, one to install the context menu and other needed things, and the other is the actual work script for processing the files.

You would need to change some of these things a bit probably for your use.

The .bat file is the file being run.

The .ini is the settings for the batch conversion

The .bat File

"i_view32.exe" "replace\*.jpg" /ini="C:\IT Automation" /advancedbatch /convert="replace\processed images\*.jpg"

The Install Script

#RequireAdmin


If FileExists("C:\Program Files (x86)\IrfanView\i_view32.exe") Then

$key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$val = "PATH"
$PATH = RegRead($key, $val)

$sAddThisPath = "C:\Program Files (x86)\IrfanView"
$PATH = $PATH & ";" & $sAddThisPath

RegWrite($key,$val,"REG_EXPAND_SZ",$PATH)
EnvUpdate()

ElseIf FileExists("C:\Program Files\IrfanView\i_view32.exe") Then

$key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$val = "PATH"
$PATH = RegRead($key, $val)

$sAddThisPath = "C:\Program Files\IrfanView"
$PATH = $PATH & ";" & $sAddThisPath

RegWrite($key,$val,"REG_EXPAND_SZ",$PATH)
EnvUpdate()

Else
    MsgBox(0, "Black Magic Automation", "Irfanview is not Detected, Install Aborted")
    Exit
EndIf



DirCreate("C:\IT Automation")

FileInstall("C:\My Places\Scripting\AutoIT\My Scripts\Context Menu Adding\RiskProcessReplace.bat", "C:\IT Automation\RiskProcessReplace.bat", 1)
FileInstall("C:\My Places\Scripting\AutoIT\My Scripts\Context Menu Adding\IV-INI\i_view32.ini", "C:\IT Automation\i_view32.ini", 1)
FileInstall("C:\My Places\Scripting\AutoIT\My Scripts\Context Menu Adding\BatchConvert.exe", "C:\IT Automation\BatchConvert.exe", 1)

RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert")
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert", "", "REG_SZ", "Auto Batch Convert")
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert", "Extended", "REG_SZ", "")
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert", "Icon", "REG_SZ", '"C:\IT Automation\BatchConvert.exe"')
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert\command")
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert\command", "", "REG_SZ", 'C:\Windows\explorer.exe "C:\IT Automation\BatchConvert.exe"')

MsgBox(0, "Black Magic Automation", "Install is Completed, Shift Right Click Folders to use.")

And the actual working script 

#include <file.au3>


$saveClip = ClipGet()
Send("^c")
Sleep(150)
$filesfolders = ClipGet()
ClipPut($saveClip)

DirCreate($filesfolders & "\Processed Images")
FileCopy("C:\IT Automation\RiskProcessReplace.bat", @TempDir & "\RiskProcessReplace.bat", 1)
_ReplaceStringInFile(@TempDir & "\RiskProcessReplace.bat", "replace", $filesfolders)
ShellExecute(@TempDir & "\RiskProcessReplace.bat")

Feedback is welcome, if you know a way to do this better let me know!

Of late I like  using .bat files with replace strings rather than trying any @ComSpec scripts makes life so much easier!

Share this post


Link to post
Share on other sites



Hi ViciousXUSMC,

cool Idea ! I use Irfan all the time with AutoIT because of the above mentioned reasons, your absolutely right !

couple of ideas for your your project:

  • offer a zip download with the bat's and such to make it easier for the user to install / use. 
  • your FileInstall ('s) will not work like that for anyone but you) ;)
  • anytime you (your program) install and/or change the registry you should offer an uninstall which cleans up in case the user decides to bail

Just my  $0.02 

cya,

Bill

1 person likes this

Share this post


Link to post
Share on other sites

Bill is right.

IrfanView is an excellent program I have used for many years.

Several of my programs use it.

You could do all you want in one script. A bat file is not required either.

As for registry entries, either have a checkbox in your program to set/unset them, or have shortcuts created that do that.

I tend to use both these days and provide an uninstall routine.

Basically you need a SET function and an UNSET function in your program, accessible via command-line.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Ok, was just sharing the concept more than anything but I will try to clean it up and package it for use by others.

As far as "all in one file" I suppose I could but it made sense to have an install and a run routine.

I know I can skip the .bat file but I have had a terrible time with ' " quote issues with @ComSpec if that is what you were intending, and this way where my .bat lives I or a user can easily make minor changes to the bat file to change how it functions without having to recompile the .exe

Any examples of what you recommended would be appreciated though, would like to see what I can learn. 

Share this post


Link to post
Share on other sites

First off, Thanks !  Your idea has pushed me to go ahead and make something I have needed for a while.

Second, be warned. I tend to oversimplify things . :ermm:

This is my version ( for my needs ) definitely a one trick pony but easily adaptable with any of the many options available in Irfan's Command Line

Does: Right click on any folder and resize all jpg's to 35 % and save to different folder on Desktop.

Add this to your registry here:  HKEY_CLASSES_ROOTDirectoryshell

post-56351-0-77691000-1426882549_thumb.j

Modify the default command (changing the desktop path to your own $$$$$)

C:\Program Files\IrfanView\i_view32.exe %1\*.jpg /resize=(35p,35p) /convert=C:\Users\$$$$$\Desktop\test2\*.jpg

cya,

Bill

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here's something to give you an idea.

$warn = ""

$reg = IniRead($inifle, "Context Entry", "registry", "")
If $reg = "" Then
    ; Create Registry context menu entries.
    $reg = 1
    IniWrite($inifle, "Context Entry", "registry", $reg)
    ContextEntries("set", ".azw", "Scan Ebook", @ScriptFullPath)
    ContextEntries("set", ".mobi", "Scan Ebook", @ScriptFullPath)
EndIf


If $CmdLine[0] <> "" Then
    $cmdlne = $CmdLine[1]
    If $cmdlne = "/unreg" Then
        If $reg = 1 Then
            UnregisterAssociations()
        EndIf
    Else
        ; put whatever you require here
    EndIf
EndIf

; This is not required, except for testing your script.
If $reg = 1 And (@Compiled = 0 Or StringInStr(@ScriptDir, "\AutoIt\") > 0) Then
    ;MsgBox(262192, "Error Check", "Some Text", 0)
    $warn = 1
    UnregisterAssociations()
EndIf

Exit


Func ContextEntries($job, $fext, $progname, $progpth)
    $extkey = "HKEY_CLASSES_ROOT\" & $fext
    $defval = RegRead($extkey, "")
    If $defval = "" And $job = "unset" Then
        MsgBox(262192, "Association Error", "Nothing is registered for the file extension passed.", 3)
    Else
        ; NOTE - If progran is not installed yet and thus associated, and is being run as an uncompiled
        ; script or from a path that includes '\AutoIt\' in the name, then Registry entry is created at
        ; program start, and then deleted at program exit. This is for script testing purposes only.
        ; NOTE 2 - Strictly speaking, in this instance, because both file extensions are using the same
        ; Amazon program, setup of Registry entry only needs to be run once, though it happens twice by
        ; current default code, for both create and delete. Without devoting too much thought to this,
        ; I have decided it is best to leave code as is, just in case.
        $keyname = "File." & StringReplace($progname, " ", ".")
        ;MsgBox(262192, "$keyname", $keyname, 0)
        If $defval = "" Then
            ; File extension is not associated with a program, so create association for current program.
            $ext = StringMid($fext, 2)
            $extfle = $ext & "file"
            RegWrite($extkey, "", "REG_SZ", $extfle)
        Else
            ; File extension is associated with a program already.
            $extfle = $defval
        EndIf
        $regkey = "HKEY_CLASSES_ROOT\" & $extfle & "\shell\" & $keyname
        $entry = "Use " & $progname
        $progpth = '"' & $progpth & '" ' & '"' & "%1" & '"'
        $defval = RegRead($regkey, "")
        ;
        If $job = "set" And $defval = "" Then
            ; Try to create a Registry entry for this program.
            $comkey = $regkey & "\command"
            $defval = RegRead($comkey, "")
            If $defval = $progpth Or $defval = "" Then
                ; Create a Registry entry for this program.
                RegWrite($regkey, "", "REG_SZ", $entry)
                RegWrite($comkey, "", "REG_SZ", $progpth)
            Else
                MsgBox(262192, "Association Failed", "Path of associated Program is for another location!" & @LF & "(auto exit in 3 seconds)", 3)
            EndIf
        ElseIf $job = "unset" And $defval = $entry Then
            ; Try to remove a Registry entry for this program.
            $comkey = $regkey & "\command"
            $defval = RegRead($comkey, "")
            If $defval = $progpth Then
                ; Remove a Registry entry for this program.
                RegDelete($regkey)
            Else
                ; Show warning only once, when using a script or running in AutoIt projects folder.
                If $warn = 1 Or $warn = "" Then
                    If $warn = 1 Then $warn = 2
                    MsgBox(262192, "Unset Association Failed", "Path of associated Program is for another location!" & @LF & "(auto exit in 3 seconds)", 3)
                EndIf
            EndIf
        Else
            ; Could not create or remove a Registry entry.
            If $defval <> $entry And $defval <> "" Then
                MsgBox(262192, "Association Failed", "Keyname belongs to another program! " & @LF & $defval & @LF & "(auto exit in 4 seconds)", 4)
            EndIf
        EndIf
    EndIf
EndFunc ; => ContextEntries


Func UnregisterAssociations()
    $reg = ""
    IniWrite($inifle, "Context Entry", "registry", $reg)
    ContextEntries("unset", ".azw", "Scan Ebook", @ScriptFullPath)
    ContextEntries("unset", ".mobi", "Scan Ebook", @ScriptFullPath)
EndFunc ;=> UnregisterAssociations

Hopefully I didn't miss anything or overlook something, when extracting it from a much larger script.

This is for automatically setting registry associations for two ebook extensions only (adjust as needed).

To unset, you just use the command-line, either by a shortcut with the '/unreg' parameter or some uninstaller script.

You could also have a checkbox in your program, to do the set or unset.

Comments hopefully explain well enough, why some things are the way they are.

WARNING - Obviously you need to sort out declarations (Global, etc) for variables yourself.

And don't presume the code will work without checking it first and making any required adjustments for your situational need.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Earthshine
      By Earthshine
      This is pretty useful to me at least, I hope to others. Whenever you need to poke a button or such on a GUI, you can just make calls to this UDF and instruct it how long to wait, 0 is forever, anyway, let the code to the explaining. Feel free to help expand this UDF. I plan to create new ones as I go along that support all the Win32 and .NET Controls. Ultimately, I would like to be able to fully control any type of control, this works well with most. Just an example of what you can do.
       
      The test installs and can uninstall 7-Zip 15.14 (x64) Setup.exe
      NOTE: Logger Author(s) .....: Michael Mims (zorphnog)
      ;                    the logging script can be obtained here
      ;                   https://www.autoitscript.com/forum/topic/156196-log4a-a-logging-udf/
       
       
      install_7zip_test.au3
      WaitForControls.au3
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • ChrisL
      By ChrisL
      #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> Global $g_hTreeView Global Enum $e_idOpen = 1000, $e_idSave, $e_idInfo Example() Func Example() Local $hGUI, $hItem Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) $hGUI = GUICreate("(UDF Created) TreeView Create", 400, 300) $g_hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") _GUICtrlTreeView_BeginUpdate($g_hTreeView) For $x = 1 To Random(2, 10, 1) $hItem = _GUICtrlTreeView_Add($g_hTreeView, 0, StringFormat("[%02d] New Item", $x)) For $y = 1 To Random(2, 10, 1) _GUICtrlTreeView_AddChild($g_hTreeView, $hItem, StringFormat("[%02d] New Child", $y)) Next Next _GUICtrlTreeView_EndUpdate($g_hTreeView) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam ;ConsoleWrite($GUI_RUNDEFMSG & @CRLF) ;Switch $wParam ; Case $hTreeView Local $hMenu $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $e_idOpen) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $e_idSave) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $e_idInfo) _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam) _GUICtrlMenu_DestroyMenu($hMenu) Return True ;EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_CONTEXTMENU Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch $wParam Case $e_idOpen _DebugPrint("WM_COMMAND " & $wParam & " Open") Case $e_idSave _DebugPrint("WM_COMMAND " & $wParam & " Save") Case $e_idInfo _DebugPrint("WM_COMMAND " & $wParam & " Info") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $g_hTreeView If Not IsHWnd($g_hTreeView) Then $hWndTreeview = GUICtrlGetHandle($g_hTreeView) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint In the example code I have a treeview and a context/popup menu, I can't use a conventional context menu because I need to use the treeview UDF functions.
      The WM_COMMAND never fires from the context/popup menu selection while there is a treeview using  _GuiCtrlTreeview_Create
      If you comment out _GuiCtrlTreeview_Create line you will then see the right click selection works as expected and the debug is written to the console on selection.
      Autoit Ver 3.3.14.2
      Any ideas why this combination won't work together?
      Thanks
       
    • Psyllex
      By Psyllex
      Is it possible for AutoIt to execute LALT+LSHIFT+NUMLOCK?  I've attempted the following:
       
      ;To show the desktop Send("{RWIN down}") Send("{d}") Send("{RWIN up}") WinWait(2) ;just to make sure the desktop is activated. ControlClick("", "",1[,button="left"[, clicks=2 [, x [, y]]]] ) Send("{LALT down}") Send("{CLT down}") Send("{DELETE down}") ;Send("{LSHIFT down}") ;Send("{NUMLOCK}") ;Send("{NUMLOCK}") ;Send ("{LALT up}") ;Send("{LSHIFT up}") This should bring up the MouseKeys dialog...but I'm getting nothing.  Thanks for any help!
    • WalkHappy
      By WalkHappy
      Hello, I'm in the process of recreation-ally expanding my Auto-it experience for some future awesome presentation-Al capabilities. So I have a user interface which loads a text document onto a GUI-object. The variables of this function are 1) The text document is dynamic in font size and face; giving the viewer an unpredictable horizontal/vertical scroll dimension. 2) The main objective is to animate the vertical scroll-bar so that it moves like the end of a movie with accreditation. 3) I'm trying to limit the accessibility in observation by excluding any mouse functions within the animation process. Any help would be greatly appreciated! Been trying to work on this for days now - from getting element properties, to embedding external code, and even exploiting ("$oIE.navigate") to loading several awkwardly formatted text documents in sequential order just to imitate a slightly offensive animation scheme. Anyways... Suggestions and comments welcomed please!!
      Script is from [Function GUICreate] - Doc:
      GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) GUICtrlCreateObj($oIE, 10, 40, 600, 360) $idButton_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30) $idButton_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30) $idButton_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30) $idButton_Stop = GUICtrlCreateButton("Stop", 330, 420, 100, 30) GUISetState(@SW_SHOW) ;Show GUI After this.. This is the window that pop's-up: