Why isn't this Windows registry command working?

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?

Brandon Johnson

Posted 2016-05-31T16:12:15.290

Reputation: 11

Answers

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.

Ƭᴇcʜιᴇ007

Posted 2016-05-31T16:12:15.290

Reputation: 103 763

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\""

Brandon Johnson

Posted 2016-05-31T16:12:15.290

Reputation: 11

1Thanks 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 – 2016-05-31T17:12:48.037

Yep just added them – Brandon Johnson – 2016-06-02T22:14:23.057

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 – 2016-06-03T03:16:43.457

-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.

Aganju

Posted 2016-05-31T16:12:15.290

Reputation: 9 103

I tried "%1" "%1" and ""%1"" but all of them still give the same error. – Brandon Johnson – 2016-05-31T16:29:45.877