6

I'm trying to create a custom context-menu entry for Windows (7) Explorer that will send ALL selected items ton ONE single command.

I've read about MultiSelectModel with a Player value in MSDN Doc but this does not seem to work. That's what I've tried:

  1. under HKEY_CLASSES_ROOT/*/shell created a key "MYVERB"
    1. (Default) for 'myverb' is 'my verb'
  2. under "MYVERB" created a key "COMMAND"
    1. (Default) for 'command' is 'python C:\MyScript.py "%1" "%2" "%3" "%4" "%5"'

This works fine for one item.

But when many items are selected, the script is launched one time for each of them. Instead, I want one only instance to receive all the selected items.

I tried adding a String Value "MultiSelectModel" -> "Player" both under "MYVERB" and "COMMAND" but the behaviour does not change.

Is what I'm trying to do even possible with a script and registry only? What am I doing wrong?

1
  • 2
    This is currently unsolved, even though I accepted Tom's answers to grant the bounty in appreciation of his efforts
    – Stefano
    Jan 4, 2012 at 16:02

2 Answers 2

0
+50

Here is an example:

HKLM\SOFTWARE\Classes\SystemFileAssociations.bmp\Shell\setdesktopwallpaper\MultiSelectModel

You don't have to specify any % parameters when you use Player, only the command itself.

You might want to try to use a script that prints the command line to a file so that you know what's happening under the hood. But I think that in this case the specification of "%1" and so on broke it...

7
  • 1
    Thanks Tom. I tried removing the parameters but still having the same problem: one command per file is launched. My command is now simply "C:\test.bat". Any other idea?
    – Stefano
    Dec 17, 2011 at 11:25
  • You might have to test to see if you are already running/just have run. There might not be a way around this.
    – soandos
    Dec 22, 2011 at 7:50
  • @Stefano: The MSDN document doesn't really mention how exactly it works, as soandos mentions it is quite possible that it just calls an application one argument at a time and that you will have to gather them and delay execution till after they are received. Do something like "if I don't get another item for 1 second, I have received everything". If you really need them all... Dec 22, 2011 at 12:21
  • @zenpoy: Why are you commenting on the answer and not the question, you just sent your comment only to me. Furthermore, you can write a script that prints out more to figure out the right way. I don't see what's wrong about the mentioned registry key so it is correct. The above is an example for setdesktopwallpaper which I have tested and works... Jul 17, 2012 at 13:09
  • @TomWijsman - I'm referring to the fact the OP said that the problem wasn't solved. I got to this page because I encounter the same problem , during the research I read that static verbs will always be launched multiple times, for each selected item. To achieve the desired behavior one need to implement a dynamic verb (compile a dll) and to register it.
    – zenpoy
    Jul 17, 2012 at 13:21
0

This is a workaround for Chrome to open multiple files.

Replace the chrome.exe path with your program and registry key or you can leave the registry key as it is.

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=============
#NoEnv
SetWorkingDir %A_ScriptDir%
#Warn
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
SetTitleMatchMode Fast
DetectHiddenWindows Off
DetectHiddenText On
#WinActivateForce
#NoTrayIcon
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -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 Force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

ContextMenuCreateFile:
FileDelete, reg.txt
FileAppend, , reg.txt
ExitApp
Return"
)  ; contextMenuCreateFileAhk
FileDelete, Context Menu Create File.exe  ; DEL Context Menu Create File.exe
FileDelete, Context Menu Create File.ahk  ; DEL Context Menu Create File.ahk
FileAppend, %contextMenuCreateFileAhk%, Context Menu Create File.ahk  ; MAKE Context Menu Create File.ahk
RunWait, C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe /in "Context Menu Create File.ahk" /out "Context Menu Create File.exe"  ; Convert AHK to EXE
FileDelete, Context Menu Create File.ahk  ; DEL Context Menu Create File.ahk
AddToContextMenu:  ; =============AddToContextMenu=============
path := ""  ; path
program := "Context Menu Create File"  ; program
contextMenu := "Open With Chrome"  ; contextMenu
regPath := "HKCR\*\shell"  ; regPath
StringReplace, regKey, contextMenu, %A_Space%, , A  ; regKey
regKey := 0 regKey  ; regKey
Loop, 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 """ /f
reg add """ regPath "\" regKey "\command"" /ve /t REG_SZ /d ""\""" path "\""`"" /f"
)  ; Registry
FileDelete, Add To Context Menu.bat  ; CREATE Add To Context Menu.bat
FileAppend, %cmd%, Add To Context Menu.bat  ; CREATE Add To Context Menu.bat
RunWait, 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.bat
Run, regedit  ; regedit
WinWait, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; Registry
Sleep, 333
ControlSetText, Edit1, %regPath%\%regKey%\command, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPath
ControlFocus, Edit1, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPath
ControlSend, Edit1, {Enter}, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPath
ControlSend, SysListView321, {Control Down}{NumpadAdd}{Control Up}, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPath
ControlSend, SysListView321, {F5}, Registry Editor ahk_class RegEdit_RegEdit ahk_exe regedit.exe  ; regPath
MsgBox, 262192, CHECK, Check If Added %contextMenu% To Registry  ; CHECK
CreateStartupShortcut:  ; =============CreateStartupShortcut=============
path := ""  ; path
program := contextMenu  ; program
Loop, Files, %program%.exe, F  ; Find Program.exe In Current Dir
{
    path := A_LoopFileLongPath  ; Set Program Path
}
FileCreateShortcut, %path%, %A_Startup%\%program%.lnk  ; Create Startup Shortcut
Run, %A_Startup%, , Max  ; Check If Shortcut Created
Run, "%program%.exe"  ; Run Program
MsgBox, 262144, CHECK, Check If Shortcut Created  ; CHECK
ExitApp  ; ExitApp
Return
  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=============
#NoEnv
SetWorkingDir %A_ScriptDir%
#Warn
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
SetTitleMatchMode Fast
DetectHiddenWindows Off
DetectHiddenText On
#WinActivateForce
#NoTrayIcon
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .