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

    • rcmaehl
      By rcmaehl
      A UDF to connect and control a Cisco Finesse on the Local Network via it's provided HTTP API
       
      Current Features:
      Lightweight
      * Control over an agent's own login and Status  
      PLANNED Features:
      Heavyweight
      * Large feature set, containing most HTTP API functions
      * Control over own Status as well as Supervisor functionality
        Helpful Premade Examples Files
      * Examples for almost every function
      * Premade CUI and GUI clients showing 
        Ready for all users, beginner and up
      * Detailed Error Reporting to help pin-point problems
      * Thorough parameter checking to prevent accidental script crashes
    • boomingranny
      By boomingranny
      ;****************************************************************** ;Spotify Automation: Start spotify and play a playlist ;v1.01 27/04/2018 ;------------------------------------------------------------------ ;by Daniel Barnes ;------------------------------------------------------------------ ;v1.01 27/04/2018 ;restarts spotify if it fails the first time ;works on computers that minimize Spotify to tray ;instead of closing it, and have a different ui element selected ;such as the Devices available option when spotify is started ;------------------------------------------------------------------ ;v1.00 25/04/2018 ;initial version ;------------------------------------------------------------------ ;Replace the below with the Spotify URI ;If you right click the playlist> share> copy spotify uri ;you can find the uri $spotifyURI = "spotify:user:12177300374:playlist:0iaTAvHRSaIkD23ofl2tck" ;****************************************************************** ;if this script breaks in the future, figure this out using the AutoIt Window Info Tool Const $SpotifyWindowIdentifier = "[Title:Spotify;Class:Chrome_WidgetWin_0]" ;NOTE ABOUT SHUFFLE: ;I couldn't automate turning shuffling on or off ;I can toggle it, but I cannot figure out the current state ;If you want to shuffle, turn on shuffle in Spotify prior ;to running this script PlaySpotifyPlaylist($spotifyURI) Func PlaySpotifyPlaylist($spotifyURI,$retry = 0) ;terminate spotify process on subsequent attempts If $retry Then echo ("Closing existing Spotify process") ProcessClose("Spotify.exe") endif echo ("Launching Spotify URI") ShellExecute($spotifyURI) ;Pause any existing song playing (if there is any) ;this is because Spotify's window title is only 'Spotify' when it is not playing any songs If Not WinExists($SpotifyWindowIdentifier) Then echo ("Pausing existing song (To find spotify window)") $timer = TimerInit() While Not WinExists($SpotifyWindowIdentifier) Send("{MEDIA_PLAY_PAUSE}") Sleep(500) If TimerDiff($timer) > 5 * 1000 Then ErrorMsg ("Timed out trying pause existing song") WEnd endif ;Get Spotify Window Handle $hwndSpotify = WinGetHandle($SpotifyWindowIdentifier) echo ("Attempting to play playlist") $timer = TimerInit() While WinGetTitle($hwndSpotify) = "Spotify" ;once it is playing the song, the title changes to the name of the song WinActivate($hwndSpotify) ControlSend($hwndSpotify,"","","{ENTER}") ;space will play what was previously playing (even another playlist or song), enter will play the playlist ;) Sleep(1000) If TimerDiff($timer) > 5 * 1000 Then If $retry Then ErrorMsg ("Timed out trying to play playlist") else Return PlaySpotifyPlaylist($spotifyURI,$retry+1) endif endif WEnd EndFunc Func echo($text) ConsoleWrite ($text&@CRLF) EndFunc Func ErrorMsg($text) MsgBox(16,StringTrimRight(@ScriptName,4),$text) Exit EndFunc  
    • 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)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • cahsobo
      By cahsobo
      Hello,

      I need help inserting these keys and values to registry
       
      [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectDraw\Compatibility\WK.1.exe]
      "Flags"=hex:00,08,00,00
      "ID"=hex:ec,33,74,3b
       
      Still can't figure out how...
    • nitron
      By nitron
      Hy to all, 
      I am really Sorry to come up with this question but i can't seem to solve the Problem.
      Its quite easy, I have been using RegNumKey for Years, but i seemed to lose track of something.
      For $ZaehlerLocal = 1 to 1200
            $RegKey = RegEnumKey("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall", $ZaehlerLocal)
            If @error <> 0 then ExitLoop
            $RegKey2=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"DisplayName")
            $RegKey3=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"UninstallString")
            $RegKey4=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"QuietUninstallString")

            if StringInStr($RegKey,"_Office15")==0 and StringInStr($RegKey2,"(German) 2013")==0 and StringInStr($RegKey,".KB")==0 and StringInStr($RegKey2,"Security update")==0 and StringInStr($RegKey2,"Framework")==0 Then
              FileWrite($FileHandleLocal,$RegKey&";")
              FileWrite($FileHandleLocal,$RegKey2&";")
              FileWrite($FileHandleLocal,$RegKey3&";")
              FileWriteline($FileHandleLocal,$RegKey4&";")
           EndIf
         Next
       
      Ive been using this to get all uninstall Strings from the Registry but for some reason, this doesn't work anymore. 
      I get some keys but not all, nore does it start with the first registry.
      As you can see in the picture, the Registry starts with {13DA9C7C-EBFB-40D0-94A1-55B42883DF21}
      but RegNumKey starts with Adressbook.
      Any Ideas what I am doing wrong? I tried HKLM64 instead as well, but with same result.
      Again sorry to bother, but i can't Find the mistake.
       

×