Jump to content
ViciousXUSMC

Irfanview Right Click Context Menu Batch Processing

Recommended Posts

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

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.


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

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

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

    • By joseLB
      Hi
      This piece of code creates and reads OK a key at  "HKEY_LOCAL_MACHINE" and can be changed for a key at "HKEY_CURRENT_USER"
      $sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav", "REG_SZ", "5555") MsgBox(4096,"wrote", $sta &@cr& @error) $zz= RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav") MsgBox(4096,"readed","="&$zz &@cr& @error) Exit With  HKEY_CURRENT_USER, in RegEdit we can see the created key, and we can create the key by hand/RegEdit and everything Works OK.
      At  HKEY_LOCAL_MACHINE we can´t see the created key above  thru RegEdit, but it Works (even not seeing, I can read). But  if I create "by hand"/RegEdit  the key,  it can´t read it with   $zz= RegRead  ("HKEY_LOCAL_MACHINE.... above.
      I´m the PC´s WIN.7 administrator. Even so I ran RegEdit as administrator and also the compiled AU3 and also plain. No changes.
      edit: even if Try   "HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", the same holds true.
      $sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", "REG_SZ", "4444") MsgBox(4096,"wrote", $sta &@cr& @error) $zz= RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav") MsgBox(4096,"readed","="&$zz &@cr& @error) Exit Seems that it creates this key at another place.... I can read the above value ("4444"), even after a boot, even the key not showing in regedit. And if I create it by hand key AAA/wav with a distinct value (666), t, it continues Reading the old value = 444.
      Thanks
      Jose
       
    • 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 v3.1.zip  (see detail at Post #37)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • 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
    • By nacerbaaziz
      good morning everybody.
      today i liked to share an small example with you
      which it an function to read the registry values as an array
      the result array is 2d array witch
      $a_array[n][0] = value name
      $a_array[n][1] = value Data
      $a_array[0][0] = values count
      here's the function

      #include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local $a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then     MsgBox(16, "error", @error)     Exit EndIf _ArrayDisplay($a_array) Func _RegReadToArray($s_RegKey)     Local $a_KeySplitInfo = StringSplit($s_RegKey, "\\", 2)     If UBound($a_KeySplitInfo) <= 1 Then         $a_KeySplitInfo = StringSplit($s_RegKey, "\", 2)         If UBound($a_KeySplitInfo) <= 1 Then Return (1, 1, 0)     EndIf     Local $H_KeyInfo = "", $s_RegKeyInfo = ""     Switch $a_KeySplitInfo[0]         Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64"             $H_KeyInfo = $HKEY_LOCAL_MACHINE         Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64"             $H_KeyInfo = $HKEY_CURRENT_USER         Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64"             $H_KeyInfo = $HKEY_CLASSES_ROOT         Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64"             $H_KeyInfo = $HKEY_USERS         Case Else             Return SetError(2, 2, 0)     EndSwitch     _ArrayDelete($a_KeySplitInfo, 0)     $s_RegKeyInfo = _ArrayToString($a_KeySplitInfo, "\")     Local $H_KeyInfoOpen = _WinAPI_RegOpenKey($H_KeyInfo, $s_RegKeyInfo, $KEY_READ)     Local $A_KeyInfo = _WinAPI_RegQueryInfoKey($H_KeyInfoOpen)     If @error Then Return SetError(1, 1, 0)     _WinAPI_RegCloseKey($H_KeyInfoOpen)     Local $A_RegVal[$A_KeyInfo[2] + 1][2]     Local $iV = 1, $s_RegRead = ""     While 1         $s_RegVal = RegEnumVal($s_RegKey, $iV)         If @error <> 0 Then ExitLoop         $s_RegRead = RegRead($s_RegKey, $s_RegVal)         If Not (@error) Then             $A_RegVal[$iV][0] = $s_RegVal             $A_RegVal[$iV][1] = $s_RegRead         EndIf         $iV += 1     WEnd     $A_RegVal[0][0] = UBound($A_RegVal) - 1     If $A_RegVal[0][0] >= 1 Then         Return $A_RegVal     Else         Return SetError(3, 3, 0)     EndIf EndFunc   ;==>_RegReadToArray
      i hope you benefit from it
      with my greetings
    • By Simpel
      Hi,
      I wondered why negative integers I wrote into registry (e.g. negative x-coordinates of a gui if using two monitors and the right one is the main one) wouldn't return right when reading. Now I know: it is saved as an unsigned integer (without algebraic sign). So here is a snippet that is changing unsigned to signed integer:
      Global Const $g_sRegKey = "HKEY_CURRENT_USER\Software\" & @ScriptName ; path to registry RegWrite($g_sRegKey, "Value", "REG_DWORD", -2147483647) ; write some negative integer into registry; -2147483647 highest possible negative integer , 2147483648 highest possible positive integer if talking of 32bit Local $sValue = RegRead($g_sRegKey, "Value") ; read out registry ConsoleWrite("Value: " & $sValue & @CRLF) ; show real value in console Local $sResult = _SignedInteger($sValue) ; change to signed value ConsoleWrite("Result: " & $sResult & @CRLF) ; and show it in console Func _SignedInteger($iUnsignedInteger) Local $iSignedInteger If $iUnsignedInteger > (2^31) Then ; then it means a negative integer $iSignedInteger = $iUnsignedInteger - (2^32) Else $iSignedInteger = $iUnsignedInteger EndIf Return $iSignedInteger EndFunc It took me some time to find out the problem and so I hope I can help somebody with this.
      Regards, Conrad
×
×
  • Create New...