Quantcast
Viewing all articles
Browse latest Browse all 13

Answer by Mister Robato for Open With on multiple files?

SUMMARY

  1. In Registry put the target program as Context Menu Create File.exe which writes reg.txt file.

  2. In your main program loop every 1 second to check if reg.txt exists. If it exists, kill the Context Menu Create File.exe and delete the reg.txt file. Then copy the selected file paths and manipulate with them.

  3. If your program loops to check for reg.txt, then you need to start the program before executing context menu either on startup or manually.

I did this with AutoHotkey.

These 2 AutoHotkey scripts below allow you to add a Open With Chrome context menu item in Windows Explorer to open multiple selected files.

You can leave all variable values as they are, but if you want to change the contextMenu value and program name then see 3.1.

INSTRUCTIONS:

Create 2 files in the same directory:

  1. Create 1st program Add To Context Menu And Create Startup Shortcut.ahk

    1. RunAsAdmin Label ensures that the script runs as admin (fixes adding Registry values).

      1. The If (!A_IsAdmin) checks if current user is NOT admin, A_IsAdmin is a built in AutoHotkey variable that returns 1 if user is admin, 0 otherwise.
      2. Run, \*RunAs "%A_ScriptFullPath%"*RunAs parameter runs the script as admin, "%A_ScriptFullPath%" gets the full path of the current executing script.
      3. ExitApp exits the current script instance running without admin privileges.
      4. Because the Run command runs the script again with admin privileges it will skip the IF condition and continue executing code below.
    2. ContextMenuCreateFile: Label creates a Context Menu Create File.exe which creates a file reg.txt and exits Context Menu Create File.exe after it has written the file reg.txt. Make sure you specify where your Ahk2Exe.exe path is in the RunWait command.

    3. Add To Context Menu: Label adds the Registry entry which runs Context Menu Create File.exe.

      1. Set the contextMenu variable to what needs to be displayed in the Context Menu. (The program name is set to contextMenu)
      2. Set the regPath to your desired Registry path.
      3. When it executes the MsgBox, check if the command is added to the Registry in the address bar.
    4. CreateStartupShortcut: Label creates the shortcut of the main program Open With Chrome.exe in Startup folder.

Add To Context Menu And Create Startup Shortcut.ahk

; =============Recommended Settings=============#NoEnvSetWorkingDir %A_ScriptDir%#WarnCoordMode, Mouse, WindowSendMode Input#SingleInstance ForceSetTitleMatchMode 2SetTitleMatchMode FastDetectHiddenWindows OffDetectHiddenText On#WinActivateForce#NoTrayIconSetControlDelay 1SetWinDelay 0SetKeyDelay -1SetMouseDelay -1SetBatchLines -1#Persistent#MaxThreadsPerHotkey 2; =============Recommended Settings=============AddToContextMenuAndCreateStartupShortcut:RunAsAdmin:  ; =============RunAsAdmin=============If (!A_IsAdmin)  ; IF NOT Admin{    Run, *RunAs "%A_ScriptFullPath%"  ; Run script as admin    ExitApp  ; Exit the current instance running without admin privileges}ContextMenuCreateFile:  ; =============ContextMenuCreateFile=============contextMenuCreateFileAhk := (LTrim"#NoEnv#NoTrayIcon#SingleInstance ForceSetWorkingDir %A_ScriptDir%SetBatchLines -1ContextMenuCreateFile:FileDelete, reg.txtFileAppend, , reg.txtExitAppReturn")  ; contextMenuCreateFileAhkFileDelete, Context Menu Create File.exe  ; DEL Context Menu Create File.exeFileDelete, Context Menu Create File.ahk  ; DEL Context Menu Create File.ahkFileAppend, %contextMenuCreateFileAhk%, Context Menu Create File.ahk  ; MAKE Context Menu Create File.ahkRunWait, C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe /in "Context Menu Create File.ahk" /out "Context Menu Create File.exe"  ; Convert AHK to EXEFileDelete, Context Menu Create File.ahk  ; DEL Context Menu Create File.ahkAddToContextMenu:  ; =============AddToContextMenu=============path := ""  ; pathprogram := "Context Menu Create File"  ; programcontextMenu := "Open With Chrome"  ; contextMenuregPath := "HKCR\*\shell"  ; regPathStringReplace, regKey, contextMenu, %A_Space%, , A  ; regKeyregKey := 0 regKey  ; regKeyLoop, Files, %program%.exe, F  ; Find Program.exe In Current Dir{    path := A_LoopFileLongPath  ; Set Program Path}cmd := (LTrim"reg add """ regPath "\" regKey """ /ve /t REG_SZ /d """ contextMenu """ /freg add """ regPath "\" regKey "\command"" /ve /t REG_SZ /d ""\""" path "\""`"" /f")  ; RegistryFileDelete, Add To Context Menu.bat  ; CREATE Add To Context Menu.batFileAppend, %cmd%, Add To Context Menu.bat  ; CREATE Add To Context Menu.batRunWait, Add To Context Menu.bat, , Hide  ; RUN Add To Context Menu.bat (*RunAs ADMIN)FileDelete, Add To Context Menu.bat  ; DEL Add To Context Menu.batRun, regedit  ; regeditWinWait, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; RegistrySleep, 333ControlSetText, Edit1, %regPath%\%regKey%\command, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPathControlFocus, Edit1, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPathControlSend, Edit1, {Enter}, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPathControlSend, SysListView321, {Control Down}{NumpadAdd}{Control Up}, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPathControlSend, SysListView321, {F5}, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPathMsgBox, 262192, CHECK, Check If Added %contextMenu% To Registry  ; CHECKCreateStartupShortcut:  ; =============CreateStartupShortcut=============path := ""  ; pathprogram := contextMenu  ; programLoop, Files, %program%.exe, F  ; Find Program.exe In Current Dir{    path := A_LoopFileLongPath  ; Set Program Path}FileCreateShortcut, %path%, %A_Startup%\%program%.lnk  ; Create Startup ShortcutRun, %A_Startup%, , Max  ; Check If Shortcut CreatedRun, "%program%.exe"  ; Run ProgramMsgBox, 262144, CHECK, Check If Shortcut Created  ; CHECKExitApp  ; ExitAppReturn
  1. Create 2nd program Open With Chrome.ahk which is the main program.
    1. Here a Loop is created and checks every 1 second if reg.txt exists.
    2. IfExist, reg.txt it kills the Context Menu Create File.exe and deletes the reg.txt.
    3. Then it activates explorer.exe window and copies all selected file paths to CLIPBOARD.
    4. If CLIPBOARD contains .,\ to make sure CLIPBOARD contains path "\" with extension ".".
    5. The list of selected files is saved in selectedFiles variable.
    6. The Loop below chromeParams := "" loops through selected files, gets the filePaths and surrounds them with double quotes, and StringReplace replaces the Windows path as url file path ex: C:\path\file.jpg to file:///path/file.jpg.
    7. Then the filePath is concatenated to chromeParams.
    8. StringTrimRight removes the last space from chromeParams string.
    9. Then Run, chrome.exe %chromeParams% is executed with %chromeParams% (list of selected files). (If the command doesn't open Chrome then put full path to Chrome, ex: Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe with the same parameters)

Open With Chrome.ahk

; =============Recommended Settings=============#NoEnvSetWorkingDir %A_ScriptDir%#WarnCoordMode, Mouse, WindowSendMode Input#SingleInstance ForceSetTitleMatchMode 2SetTitleMatchMode FastDetectHiddenWindows OffDetectHiddenText On#WinActivateForce#NoTrayIconSetControlDelay 1SetWinDelay 0SetKeyDelay -1SetMouseDelay -1SetBatchLines -1#Persistent#MaxThreadsPerHotkey 2; =============Recommended Settings=============OpenWithChrome:Loop  ; Loop Start{    Sleep, 1000  ; Fix High CPU    IfExist, reg.txt  ; IF reg.txt EXIST    {        RunWait, cmd /c taskkill /im "Context Menu Create File.exe" /f, , Hide  ; Fix Opening 2 Compose Windows        FileDelete, reg.txt  ; DEL reg.txt        WinActivate, ahk_class CabinetWClass ahk_exe explorer.exe  ; Explorer        CLIPBOARD := ""  ; Clear Clipboard        Send, {Control Down}{c}{Control Up}  ; Copy File Paths        ClipWait, 0  ; Clip Wait        If CLIPBOARD contains .,\  ; IF CLIPBOARD contains .,\        {            selectedFiles := CLIPBOARD  ; selectedFiles            chromeParams := ""  ; chromeParams            Loop, Parse, selectedFiles, `n, `r  ; Loop Start selectedFiles            {                filePath := """file:///" A_LoopField """"  ; filePath                StringReplace, filePath, filePath, \, /, A  ; Replace \ with /                chromeParams .= filePath . " "  ; chromeParams .= %filePath%,            }            StringTrimRight, chromeParams, chromeParams, 1  ; Remove Last Space            Run, chrome.exe %chromeParams%  ; Open Files In Chrome        }    }}Return
  1. Convert both Add To Context Menu And Create Startup Shortcut.ahk and Open With Chrome.ahk to EXE files in the same directory using Ahk2Exe.exe --> (find in Start Menu, just browse file and hit convert)

  2. Execute the Add To Context Menu And Create Startup Shortcut.exe

  3. Select files, right click and the Open With Chrome context menu item should appear.


Viewing all articles
Browse latest Browse all 13

Trending Articles