使用Visual Studio安装项目设置InstallPath注册表项

时间:2021-03-25 23:56:43

I am deploying my application using an msi installer designed with a Visual Studio Setup Project. How do I set a registry key to the application's install path?

我正在使用使用Visual Studio安装项目设计的msi安装程序部署我的应用程序。如何为应用程序的安装路径设置注册表项?

4 个解决方案

#1


One way to do this would be to create a custom action in your installer. On the custom action you could provide CustomActionData "/Path="[TARGETDIR]*". Within your custom action code you can reference Context.Parameters["Path"] and receive the installation path passed from the installer in your .NET code.

一种方法是在安装程序中创建自定义操作。在自定义操作上,您可以提供CustomActionData“/ Path =”[TARGETDIR] *“。在您的自定义操作代码中,您可以引用Context.Parameters [”Path“]并在.NET代码中接收从安装程序传递的安装路径。

Now that you have the [TARGETDIR] within your custom action code you can continue to use the Microsoft.Win32 namespace to set the registry key.

现在您的自定义操作代码中有[TARGETDIR],您可以继续使用Microsoft.Win32命名空间来设置注册表项。

HTH - Wil

HTH - Wil

#2


Actually, while I was searching for the same thing the following solution was also mentioned:

实际上,当我在搜索同样的东西时,还提到了以下解决方案:

use [TARGETDIR] in the registry key.

在注册表项中使用[TARGETDIR]。

#3


Just to add to putting [TARGETDIR] in the registry key as the value. If you are using the install shield for vs2012 use [INSTALLDIR] instead in the registry key.

只是添加将[TARGETDIR]作为值添加到注册表项中。如果您使用vs2012的安装屏蔽,请在注册表项中使用[INSTALLDIR]。

#4


  1. follow this steps :
  2. 按照以下步骤:

  3. Add a class library project into setup solution.
  4. 将类库项目添加到安装解决方案中。

  5. Add installer file into your class library project.
  6. 将安装程序文件添加到类库项目中。

  7. Add created class library project to your setup application folder
  8. 将创建的类库项目添加到安装应用程序文件夹中

  9. Add created project installer file (On setup custom action window) to "Install" sub tree item.
  10. 将创建的项目安装程序文件(在安装程序自定义操作窗口中)添加到“安装”子树项目。

使用Visual Studio安装项目设置InstallPath注册表项

  1. click on added project and press F4 to open Property window.
  2. 单击添加的项目,然后按F4打开“属性”窗口。

  3. on property window set "/pDir="[TARGETDIR]\" into CustomActionData.
  4. 在属性窗口中将“/ pDir =”[TARGETDIR] \“设置为CustomActionData。

使用Visual Studio安装项目设置InstallPath注册表项

  1. on installer file (in class library project) write the follow code to write install path into registry.

    在安装程序文件(在类库项目中)编写以下代码以将安装路径写入注册表。

     Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)
        Dim regsrv As New RegistrationServices
        regsrv.RegisterAssembly(MyBase.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase)
        '--------- adding installation directory to stateSaver ----------
        stateSaver.Add("myTargetDir", Context.Parameters("pDir").ToString)
    End Sub
    
    Public Overrides Sub Commit(ByVal savedState As System.Collections.IDictionary)
        MyBase.Commit(savedState)
        ''messagebox.show("salam")
        Dim InstallAddress As String = savedState("myTargetDir").ToString
        Dim regKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software\pourab\Sanjande", True)
        regKey.SetValue("InstalledFolder", InstallAddress)

#1


One way to do this would be to create a custom action in your installer. On the custom action you could provide CustomActionData "/Path="[TARGETDIR]*". Within your custom action code you can reference Context.Parameters["Path"] and receive the installation path passed from the installer in your .NET code.

一种方法是在安装程序中创建自定义操作。在自定义操作上,您可以提供CustomActionData“/ Path =”[TARGETDIR] *“。在您的自定义操作代码中,您可以引用Context.Parameters [”Path“]并在.NET代码中接收从安装程序传递的安装路径。

Now that you have the [TARGETDIR] within your custom action code you can continue to use the Microsoft.Win32 namespace to set the registry key.

现在您的自定义操作代码中有[TARGETDIR],您可以继续使用Microsoft.Win32命名空间来设置注册表项。

HTH - Wil

HTH - Wil

#2


Actually, while I was searching for the same thing the following solution was also mentioned:

实际上,当我在搜索同样的东西时,还提到了以下解决方案:

use [TARGETDIR] in the registry key.

在注册表项中使用[TARGETDIR]。

#3


Just to add to putting [TARGETDIR] in the registry key as the value. If you are using the install shield for vs2012 use [INSTALLDIR] instead in the registry key.

只是添加将[TARGETDIR]作为值添加到注册表项中。如果您使用vs2012的安装屏蔽,请在注册表项中使用[INSTALLDIR]。

#4


  1. follow this steps :
  2. 按照以下步骤:

  3. Add a class library project into setup solution.
  4. 将类库项目添加到安装解决方案中。

  5. Add installer file into your class library project.
  6. 将安装程序文件添加到类库项目中。

  7. Add created class library project to your setup application folder
  8. 将创建的类库项目添加到安装应用程序文件夹中

  9. Add created project installer file (On setup custom action window) to "Install" sub tree item.
  10. 将创建的项目安装程序文件(在安装程序自定义操作窗口中)添加到“安装”子树项目。

使用Visual Studio安装项目设置InstallPath注册表项

  1. click on added project and press F4 to open Property window.
  2. 单击添加的项目,然后按F4打开“属性”窗口。

  3. on property window set "/pDir="[TARGETDIR]\" into CustomActionData.
  4. 在属性窗口中将“/ pDir =”[TARGETDIR] \“设置为CustomActionData。

使用Visual Studio安装项目设置InstallPath注册表项

  1. on installer file (in class library project) write the follow code to write install path into registry.

    在安装程序文件(在类库项目中)编写以下代码以将安装路径写入注册表。

     Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)
        Dim regsrv As New RegistrationServices
        regsrv.RegisterAssembly(MyBase.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase)
        '--------- adding installation directory to stateSaver ----------
        stateSaver.Add("myTargetDir", Context.Parameters("pDir").ToString)
    End Sub
    
    Public Overrides Sub Commit(ByVal savedState As System.Collections.IDictionary)
        MyBase.Commit(savedState)
        ''messagebox.show("salam")
        Dim InstallAddress As String = savedState("myTargetDir").ToString
        Dim regKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software\pourab\Sanjande", True)
        regKey.SetValue("InstalledFolder", InstallAddress)