0

So I'm trying to make a right click context menu option that will copy the path of a file in Windows 7. This is my registry stuff:

[HKEY_CLASSES_ROOT\*\shell\Copy path]

[HKEY_CLASSES_ROOT\*\shell\Copy path\command]
@="C:\Windows\System32\Tweaks\ContextCopy.exe path %1"

The option correctly shows up in the context menu. ContextCopy.exe takes a the file's absolute path as a string and internally copies it to the clipboard depending on what the first argument is. It works fine as I've tested it from the command prompt with an actual filename for the last argument. But whenever I do it from the context menu, I get an error pop up that says "This file does not have a program associated with it for performing this action." And the title of this pop up is the path of the file that I right clicked and opened the menu on. The path is also not copied to the clipboard.

I think %1 should give the file's absolute path as a string, right?

2

You can try including quotes around the %1 to ensure that paths with spaces are treated as a single string.

So via Regedit change the command to:

C:\Windows\System32\Tweaks\ContextCopy.exe path "%1"

Which will export as:

[HKEY_CLASSES_ROOT\*\shell\Copy path]

[HKEY_CLASSES_ROOT\*\shell\Copy path\command]
@="C:\Windows\System32\Tweaks\ContextCopy.exe path \"%1\""

The back slashes escape the nested quotes.

Also, since you're using Windows 7, you don't actually need your little ContextCopy.exe utility, as you can use windows' in-built clip command:

From clip /?:

CLIP

Description: Redirects output of command line tools to the Windows clipboard. This text output can then be pasted into other programs.

Parameter List:

/?                  Displays this help message.

Examples:

DIR | CLIP          Places a copy of the current directory
                    listing into the Windows clipboard.

CLIP < README.TXT   Places a copy of the text from readme.txt
                    on to the Windows clipboard.

So you could replace the Command with something like cmd.exe /c echo "%1"|clip and get the same effect, without the 3rd party utility.

0

I got it. I needed to escape the backslashes in the .exe path and also the quotes around the %1:

[HKEY_CLASSES_ROOT\*\shell\Copy path]

[HKEY_CLASSES_ROOT\*\shell\Copy path\command]
@="C:\\Windows\\System32\\Tweaks\\ContextCopy.exe path \"%1\""
  • 1
    Thanks for closing the loop on your question. To make the answer clearer for others with a similar problem, can you add the actual resulting commands? – fixer1234 May 31 '16 at 17:12
  • Yep just added them – Brandon Johnson Jun 2 '16 at 22:14
  • In the site's Q&A format, questions are limited to just the question and the solutions go in the answers. I went ahead and moved it for you. If you accept your answer or one of the others, it will indicate that the problem has been solved. To do that, click on the checkmark next to the answer you consider the solution. – fixer1234 Jun 3 '16 at 3:16
-1

You need (at least) add quotes around the %1 - "%1" - otherwise your filepath and name will arrive as separate parameters wherever they have a blank.

  • I tried \"%1\" "%1" and ""%1"" but all of them still give the same error. – Brandon Johnson May 31 '16 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.