SUMMARY
In Registry put the target program as Context Menu Create File.exe which writes reg.txt file.
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.
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 andprogram
name then see 3.1.
INSTRUCTIONS:
Create 2 files in the same directory:
Create 1st program Add To Context Menu And Create Startup Shortcut.ahk
RunAsAdmin
Label ensures that the script runs as admin (fixes adding Registry values).- 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. Run, \*RunAs "%A_ScriptFullPath%"
*RunAs parameter runs the script as admin, "%A_ScriptFullPath%" gets the full path of the current executing script.ExitApp
exits the current script instance running without admin privileges.- Because the
Run
command runs the script again with admin privileges it will skip theIF
condition and continue executing code below.
- The
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 yourAhk2Exe.exe
path is in theRunWait
command.Add To Context Menu:
Label adds the Registry entry which runs Context Menu Create File.exe.- Set the
contextMenu
variable to what needs to be displayed in the Context Menu. (Theprogram
name is set tocontextMenu
) - Set the
regPath
to your desired Registry path. - When it executes the
MsgBox
, check if the command is added to the Registry in the address bar.
- Set the
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
- Create 2nd program Open With Chrome.ahk which is the main program.
- Here a
Loop
is created and checks every 1 second if reg.txt exists. IfExist, reg.txt
it kills the Context Menu Create File.exe and deletes the reg.txt.- Then it activates explorer.exe window and copies all selected file paths to CLIPBOARD.
If CLIPBOARD contains .,\
to make sure CLIPBOARD contains path "\" with extension ".".- The list of selected files is saved in
selectedFiles
variable. - The Loop below
chromeParams := ""
loops through selected files, gets thefilePath
s and surrounds them with double quotes, andStringReplace
replaces the Windows path as url file path ex:C:\path\file.jpg
tofile:///path/file.jpg
. - Then the
filePath
is concatenated tochromeParams
. StringTrimRight
removes the last space fromchromeParams
string.- 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)
- Here a
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
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)
Execute the
Add To Context Menu And Create Startup Shortcut.exe
Select files, right click and the Open With Chrome context menu item should appear.