Windows – Using Environment variable in registry for command

context menuenvironment-variableswindowswindows-registry

I'm making a program which requires arguments from context menu (click a file and invoke my program with the file name as parameter).

I'm trying to add a registry key to …\shell\myThing\command. What I'd like to is the following:

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

I'd like to use %ProgramFiles(x86)% environment variable, because I've read somewhere that it works on x86 and x64 Windows as well. (Changing to "normal" Program Files on x86.)
The problem comes when I try to set:

%ProgramFiles(x86)%\Feliratozo\Feliratozo.exe %1

This way when I try to use the said context menu item, it gives the following error:

Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.

The permission problem doesn't seem to be correct because when using absolute path it works.

What can I do now?

Best Answer

You should remember to make the registry value a REG_EXPAND_SZ instead of a REG_SZ. Normally, only REG_EXPAND_SZ values are expanded.

Related Question