Question

My application is a sort of "scripting" system. I've made the "scripts" usable as drop targets using info from this answer, however, the default action is to open the script for editing. To run it, you need to pass a /r argument. Is there any way to either: a. use the Run verb, or b. pass the extra argument?

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob]
@="MyApp Job"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shell]
@="open"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shell\open\command]
@="\"C:\\Program Files\\MyApp\\MyApp.exe\" \"%1\" \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shell\Run]
@="&Run"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shell\Run\command]
@="\"C:\\Program Files\\MyApp\\MyApp.exe\" /r \"%1\" \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shellex]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MyAppJob\shellex\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.myJob]
@="MyAppJob"

(Program names have been changed above.)

I've tried adding a key "Verb"="Run" to the DropHandler subkey, but of course, it isn't that simple.

I know I could set Run as the default verb, but I'd prefer not to have to if at all possible.

Was it helpful?

Solution

Ok, the answer, as suggested in comments, was to create my own ShellExtension dll. I took a look at the microsoft provided example, but it wouldn't compile, and an example on CodeProject didn't make much sense (I think it was written for a different version of VS).

After some googling, however, I discovered this C# codeproject tutorial, which introduced me to SharpShell, which is a C# library for shell extensions. This simplified matters a whole lot:

[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".myjob")]
public class MyAppDropHandler : SharpDropHandler
{
    protected override void DragEnter(DragEventArgs dragEventArgs)
    {
        dragEventArgs.Effect = DragDropEffects.Move;
    }

    protected override void Drop(DragEventArgs dragEventArgs)
    {
        new Process
        {
            StartInfo =
            {
                FileName = this.SelectedItemPath,
                Verb = "Run",
                Arguments = String.Join(" ", list.Select(s => String.Format("\"{0}\"", s)))
            }
        }.Start();
    }
}

I then followed the instructions for registering the extension here, and it appears to work great.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top