c# - 如何在安装应用程序的 hkey_classes_root 键上添加值

标签 c# registry windows-installer url-protocol visual-studio-setup

解决!!

我正在尝试为我的应用程序创建一个自定义 URL 协议(protocol),当他们访问或单击指向 myapp:start 的链接时将启动我的应用程序

我的问题是如何知道用户安装我的应用程序的位置。 msi 安装程序可以在注册 HKEY_CLASSES_ROOT 到注册表时放置位置吗?

HKEY_CLASSES_ROOT
   myapp
      (Default) = "URL:myapp Protocol"
      URL Protocol = ""
      DefaultIcon
           (Default) = "myapp.exe,1"
      shell
           open
               command
                   (Default) = "C:\Program Files\MyAppFolder\MyApp.exe" "%1"

我想将路径“C:\Program Files\MyAppFolder\MyApp.exe”更改为用户在安装过程中安装我的应用程序的位置。

解决方案

HKEY_CLASSES_ROOT
   myapp
      (Default) = "URL:myapp Protocol"
      URL Protocol = ""
      DefaultIcon
           (Default) = "myapp.exe,1"
      shell
           open
               command
                   (Default) = "[TARGETDIR]MyApp.exe "%1""

[TARGETDIR] 将自动更改为用户安装文件的位置,例如"C:\Program Files\MyAppFolder\"

有关更多信息,请单击此链接 -> Registering an Application to a URI Scheme

最佳答案

通过 Visual Studio 安装项目,您可以在创建注册表项时使用 [TARGETDIR] 变量。

此变量会自动设置为您的应用程序安装到的目标目录,只需将您的 .exe 文件附加到末尾即可。

关于c# - 如何在安装应用程序的 hkey_classes_root 键上添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15336711/

相关文章:

c# - 从 WiX 安装程序传递标志以合并模块?

WiX:InstallUISequence 和 InstallExecuteSequence 之间的属性值丢失

javascript - 如何从 WebAPI Controller 使用 javascript 函数发送 JSON(不带引号)

windows - POWERSHELL - WINDOWS 注册表 - 如何拥有 "*"的路径,如 'hkcr:\*\shell'

java - RMI 中命名和注册表的区别

c++ - 安装 Windows 服务 C++

vbscript - 我的 MSI 安装程序的 vbscript 有什么问题?

c# - ExceptionHandling : If controller method returns json then return json, if View then return Redirect

c# - MySQL日期格式问题

c# - EF-core OnModelCreating 方法中的依赖注入(inject)