I'm trying to write a registry hack that will streamline some of my setup tasks when I create a new VM or repave my laptop. One thing I'm doing is switching to portable versions (synced in Dropbox) of a bunch of my favorite apps, including Notepad++.
I want to create a registry entry to allow me to have the Open with Notepad++ option in my right click menu, which is the only thing I'm missing with the portable version. I'm getting an error, though:
Windows cannot access the specified device, path or file. You may not have the
appropriate permissions to access the item.
Here's my .reg
file:
[HKEY_CLASSES_ROOT\*\shell\Open with Notepad++]
"Icon"="%USERPROFILE%\\Dropbox\\Programs\\Setup\\Icons\\Notepad++.ico"
@=""
[HKEY_CLASSES_ROOT\*\shell\Open with Notepad++\command]
@="%USERPROFILE%\\Dropbox\\Programs\\Notepad++\\notepad++.exe %1"
The icon works perfectly. I can get the entry above to work fine if I hardcode C:\Users\myusername
, but I'm going for portability here.
I'm pretty sure the issue is just finding the right escape sequence for the %
symbols, but it's hard to say.
Suggestions?
EDIT: I went with the add reg
command option, and after a bit of trial and error, here's the command that worked:
reg add HKCR\*\shell\OpenWithNotepad++\command /t REG_EXPAND_SZ /ve /d ^%USERPROFILE^%"\Dropbox\Programs\Notepad++\notepad++.exe %1"
After running the command, I exported the results as a .reg
file as well. Wins all around.
Best Answer
To use (expand) environment variables in the registry, the value must be of the type
REG_EXPAND_SZ
.Based on this question, it would be easiest to add that kind of value with the
reg
command rather than a.reg
file..See
reg add /?
for more information on this syntax.You could also encode the data as hex. There's some examples of that here:
becomes