How can I format this path to work as registry key value?

C:\Program Files (x86)\DotR\DotR.exe

I know I need to escape the backslashes like C:\\Program Files (x86)\\DotR\\DotR.exe but it still doesn't work. Do I need to handle spaces and parens as special characters and if so, how?

Edit with details: I'm running a small console application from the context menu. When I save it to C:\DotR.exe and add to HKEY_CLASSES_ROOT\Folder\shell\DotR\ the value C:\\DotR.exe %1 it works fine but when I try to make it C:\\Program Files(x86)\\DotR\\DotR.exe %1 I get an error message that says application not found. I want to save it in program files and not C root.


Solution 1:

How exactly are you trying to add it?

I suspect your primary problem is that you need quotes around the name.

"C:\Program Files (x86)\DotR\DotR.exe" %1

If you are adding the value by using the regedit.exe GUI editor, as a string value, then you do not need to escape the \ or the " characters. The GUI will handle the escaping, you just need to add the quotes.

If you are adding it with a .reg file then it \ characters do need to be escaped, you also need to escape the " character. So a REG_SZ value of "c:\asdf\asdf" would look like this.

[HKEY_CURRENT_USER\Temp]
"asdf"="\"c:\\asdf\\asdf\""