3

I'm trying to add an item to context menu in Windows 10. When I use the direct path such as:

[HKEY_CLASSES_ROOT\Directory\Background\shell\MySetFolders\command] @="D:\\DOCS\\CreateFolders\\CreateFolders.exe"

It works. I have a new command in the context menu and it runs my app.

But I use an alias like below it won't run my app but an error

[HKEY_CLASSES_ROOT\Directory\Background\shell\MySetFolders\command] @="%userprofile%\\documents\\CreateFolders\\CreateFolders.exe"

What's the problem? Thank you.

P.S : "My Documents" location is set to D:\DOCS

Error

AntonU
  • 31
  • 5
  • Have you used relative path in windows registry successfully in other instances? – Argyll Mar 22 '18 at 12:48
  • Nope, only this one. I haven't added anything else. It's just weird that it works with the direct path and not with the alias – AntonU Mar 22 '18 at 15:29
  • Well I wonder exactly what is driving the context menu. Those alias should work in cmd and explorer. The error message seems to suggest it would be explorer that is used to deal with links in the context menu. So it's strange indeed. Have you tried using context menu setting softwares, set relative path there, and see how they would modify the registry? – Argyll Mar 25 '18 at 23:53
  • It does work when I paste the path into a explorer window. I just wanted to distribute my little app and make it available through the context menu. To add it into the context menu I wanted to use a Registry Editor file with the described commands. As everyone has their own accounts name it'd be better to use an alias to get to Documents folder. Hope that makes sense. I haven't tried different apps nor special software as I thought it would be quite simple. – AntonU Mar 26 '18 at 10:50
  • If it's for your own app, in the installer you make, are you able to detect what directory the user chooses and use absolute path that way? For the context menu editor softwares, I suggested it so that you can whether they do it any differently. Maybe we end up learning something there. – Argyll Mar 26 '18 at 17:11
  • 1
    The entry is expected to be a path. It is not a programming language where you can do some calculations that eventually result in a path. You are expected to do the calculations first, and then put the result in the registry. – Raymond Chen Apr 16 '18 at 04:21

1 Answers1

0

Yes, you can:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\video2mp4\command]
@="cmd /c \"\"ffmpeg.exe\" -i \"%1\" output.mp4\""

Inspired by Add current folder to reg file

rofrol
  • 14,438
  • 7
  • 79
  • 77