Jump to content
ViciousXUSMC

Irfanview Right Click Context Menu Batch Processing

Recommended Posts

ViciousXUSMC

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
l3ill

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

  • Like 1

Share this post


Link to post
Share on other sites
TheSaint

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
ViciousXUSMC

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
l3ill

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
TheSaint

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

    • RooperGee
      By RooperGee
      I had written a GUI with several buttons and I wanted one of the buttons to show its context menu regardless of the user right or left clicking the button.  The whole purpose of the button was to show the user a menu of options and a context menu fit the need just fine, but I needed it to display with either click option.  I came up with the code below to accomplish this but I feel like I might be missing some very obvious easier way to do this and I feel it's a little lame to be forcing a right click mouse action on the button as a result of the user doing a left click, but it works!
      Anyone have a suggestion of a better way to do this?  Otherwise, if this idea helps you, here you go.
      #include <GUIConstantsEx.au3> LeftClickContextTest() Func LeftClickContextTest() Local $hGUI = GUICreate("My GUI", 200, 100) Local $button = GUICtrlCreateButton("Show Context", 15, 40, 85, 25) Local $close = GUICtrlCreateButton("Close", 110, 40, 85, 25) Local $context = GUICtrlCreateContextMenu($button) GUICtrlCreateMenuItem("Test Context Item 1", $context) GUICtrlCreateMenuItem("Test Context Item 2", $context) GUICtrlCreateMenuItem("Test Context Item 3", $context) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $close ExitLoop Case $button MouseClick("right", MouseGetPos(0), MouseGetPos(1), 1, 0) EndSwitch WEnd EndFunc  
    • spikespaz
      By spikespaz
      The rule against game automation is misguided and unhelpful for the following reasons.
       
      I am a developer, using AutoIt to automate testing for a game that I am developing. Singleplayer games can be mundane and sometimes cheating can be overlooked. Multiplayer games usually have anticheat against repetitive robotic actions anyways. People want to override the control schemes of games with bad customization. Eg. Axiom Verge, Fortnite (Crouching). Game automation is not always bad. If the user feels the need to automate a singleplayer game for boring or mundane tasks, that is their choice. Similarly, if I wish to use scripts to automate testing, that is my choice.
      Game automation can be a problem for online multiplayer games, giving players a competitive advantage. This could be countered by common sense; ask OP what game they are automating, and is it an online game? What is this script for, and what does it seem to do?

      Please revise the rule as it seems very unnecessary and harmful to people seeking help with innocent attempts at game automation.
    • milkmoron
      By milkmoron
      https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373 At least we have an element title: [Entered By:] class: [WindowsForms10.EDIT.app.0.30495d1_r9_ad1] Having the following values for all properties: Title is: <Entered By:> Class := <WindowsForms10.EDIT.app.0.30495d1_r9_ad1> controltype:= <UIA_EditControlTypeId> ,<50004> , (0000C354) 322;370;736;184 *** Parent Information top down *** 3: Title is: <View Activity> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_WindowControlTypeId> ,<50032> , (0000C370) 306;72;784;605 "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 2: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;768;542 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 1: Title is: <> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;103;749;451 "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" 0: Title is: <Delete> Class := <WindowsForms10.Window.8.app.0.30495d1_r9_ad1> controltype:= <UIA_PaneControlTypeId> ,<50033> , (0000C371) 314;122;749;432 "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1"" ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;View Activity _UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ; _UIA_setVar("oP4","Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1") ;Delete _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_action("EnteredBy:.mainwindow","setfocus") ;~ *** Standard code Flexible*** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=View Activity;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Delete;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.30495d1_r9_ad1", $treescope_children) _UIA_Action($oP0,"setfocus") _UIA_setVar("EnteredBy:.mainwindow","title:=Entered By:;classname:=WindowsForms10.EDIT.app.0.30495d1_r9_ad1") _UIA_action("EnteredBy:.mainwindow","setfocus") Need some help selecting this defining it as a variable to save and then insert the text within, to the same application but different account.
    • TheSaint
      By TheSaint
      TeraCopy Timer - A program of mine, front end really, that I have been working on (on & off) for some time, but not shared here before, that I recall. Third party program TeraCopy is required.
      Many of you will be familiar with TeraCopy, and it has been discussed here at AF on several occasions, in various sub forums, including Chat.
      BE ADVISED - I still use an older version of TeraCopy (v2.27), a goody but an oldy, so have only tested my program with that. It may work with the newer v3.xx, or may be easily adjusted to do so, but I have not yet gone that route. Likewise, I only use it with Win 7 and Win XP, but I don't imagine there should be any issues with newer Windows. Add to that, my program being devised and created in AutoIt v3.3.0.0.
      So what is TeraCopy Timer and why might you need it?
      --------------------------------------------------------------------------------------
      Those familiar with TeraCopy use, know you can run multiple copy or move jobs either simultaneously or concurrently (one immediately after another has finished). With the free version at least, you have no control over precise order or timing, and no way to deal (without manual interaction) with the pesky Thumbs.db files in Win XP. TeraCopy Timer allows you to do all those things, and in a batch fashion.
      --------------------------------------------------------------------------------------
      Some screenshots and brief explanation
      Main Window
      Minimalist Window
      This new WAIT feature is the simplest and best way to use the program generally (in my view) ... but check out the following, as it is not always the case.
      Advanced Delay Window
      WARNING - It should go without saying, that you take all the usual precautions. For instance, don't use move with the only copy you have of precious files. BACKUP BACKUP BACKUP! Don't hold me liable for anything, except for being a nice guy who likes to share.
      TeraCopy Timer v2.8.zip  (see detail at Post #34)
      TeraCopy Timer v2.9.zip  (see detail at Post #35)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • 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/
       
       
       
       
      WaitForControls.au3
      install_7zip_test.au3
×