Set InstallPath registry key using Visual Studio Setup project

丶灬走出姿态 提交于 2019-12-06 17:12:29

问题


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?


回答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.

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.

HTH - Wil




回答2:


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

use [TARGETDIR] in the registry key.




回答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.




回答4:


  1. follow this steps :
  2. Add a class library project into setup solution.
  3. Add installer file into your class library project.
  4. Add created class library project to your setup application folder
  5. Add created project installer file (On setup custom action window) to "Install" sub tree item.

  1. click on added project and press F4 to open Property window.
  2. on property window set "/pDir="[TARGETDIR]\" into CustomActionData.

  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)


来源:https://stackoverflow.com/questions/1160173/set-installpath-registry-key-using-visual-studio-setup-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!