NSIS play with InstalldirRegKey

只愿长相守 提交于 2020-01-05 10:08:39

问题


From NSIS documentation, we have

root_key subkey key_name This attribute tells the installer to check a string in the registry, and use it for the install dir if that string is valid. If this attribute is present, it will override the InstallDir attribute if the registry key is valid, otherwise it will fall back to the InstallDir default.

So, if I have these lines in a .nsi file:

InstallDir "D:\myFolder\myFile"

InstallDirRegKey HKCU "Software\${PRODUCT_COMPANY}\${PRODUCT_NAME}" "Install_Dir"

I understand that I set my install directory to D:\myFolder\myFile as default directory, but if Software\${PRODUCT_COMPANY}\${PRODUCT_NAME} is a valid path, then I will use it instead. Is that correct?

From another post, I understand that the InstallDirRegKey instruction is used to overwrite previous installation at same location. How is it working more precisely? If I have the following,

InstallDir "D:\myFolder\myFile"

InstallDirRegKey HKCU "D:\myFolder\myFile" "Install_Dir"

will a new .exe file generated by the NSIS script overwrite the previous one? Or does it mean that the executable will overwrite the previous one?


回答1:


InstallDirRegKey only reads from the registry, it never writes.

Before your .onInit is executed NSIS does:

  1. If InstallDir is set, that path is copied to $Instdir
  2. If InstallDirRegKey is set and the registry key exists, the path from the registry (With the filename removed) is copied to $Instdir

So if you want InstallDirRegKey to have any effect the next time a user runs the installer you must point it to a key that your installer creates in one of your sections. It can be the UninstallString command in your uninstall key or a application specific key like HKLKM\Software\My Company\My App.

The whole point of this is that when the user re-installs or installs a new version of your app it will be installed in the same folder (overwriting/upgrading the existing install).



来源:https://stackoverflow.com/questions/13441640/nsis-play-with-installdirregkey

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