使用注册表中的环境变量进行命令

Mar*_*jes 10 windows windows-registry environment-variables context-menu

我正在制作一个需要上下文菜单中的参数的程序(单击一个文件并使用文件名作为参数调用我的程序)。

我正在尝试向 ...\shell\myThing\command 添加一个注册表项。我想要的是以下内容:

C:\Program Files (x86)\Feliratozo\Feliratozo.exe %1
Run Code Online (Sandbox Code Playgroud)

我想使用 %ProgramFiles(x86)% 环境变量,因为我在某处读到它也适用于 x86 和 x64 Windows。(在 x86 上更改为“正常”程序文件。)当我尝试设置时出现问题:

%ProgramFiles(x86)%\Feliratozo\Feliratozo.exe %1
Run Code Online (Sandbox Code Playgroud)

这样,当我尝试使用上述上下文菜单项时,会出现以下错误:

Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.
Run Code Online (Sandbox Code Playgroud)

权限问题似乎不正确,因为在使用绝对路径时它可以工作。

我现在能做什么?

Wer*_*nze 15

您应该记住将注册表值设为 REG_EXPAND_SZ 而不是 REG_SZ。通常,仅扩展 REG_EXPAND_SZ 值。

  • 如果该值恰好是“(默认)”键,您会发现无法通过注册表编辑器 GUI 更改其类型。要解决此问题,请手动创建密钥:复制/保存其当前值,从 Admin PowerShell 窗口/命令提示符运行 `reg.exe add <path-to-value> /ve /t REG_EXPAND_SZ /d "<value>" `. 瞧,您的“(默认)”键现在是“REG_EXPAND_SZ”! (4认同)
  • @IanKemp 不要忘记引用 `"<path-to-value>"` 并记住尖括号不是值的一部分 (2认同)