Code Example – NSIS – UT3 Install Locations

Along with the mod switch comes another piece of the pie. The installer allows you to package your mod for distribution. One of the hurdles that needs to be hopped over is finding UT3.exe so we can create the required shortcuts. Below is a short piece of code in NSIS to check the registry keys in windows 32 and 64 bit.

; Script generated by the HM NIS Edit Script Wizard.
SetCompressor /FINAL /SOLID lzma

OutFile "MyInstaller.exe"
InstallDir "$DOCUMENTSMy GamesUnreal Tournament 3White"

# Keys
!define INSTALL_KEY_UNK132 "SOFTWAREMicrosoftWindowsCurrentVersionUninstallInstallShield_{C019D439-E7F8-49EB-85FA-6D0C8CCBDA23}"
!define INSTALL_KEY_UNK232 "SOFTWAREMicrosoftWindowsCurrentVersionUninstallInstallShield_{A007C579-B78D-4FDE-A85A-16987A251E53}"
!define INSTALL_KEY_UNK332 "SOFTWAREMicrosoftWindowsCurrentVersionUninstallInstallShield_{FDBBAF14-5ED8-49B7-A5BE-1C35668B074D}"
!define INSTALL_KEY_UNK432 "SOFTWAREMicrosoftWindowsCurrentVersionUninstallInstallShield_{69082C6E-1944-4EAD-B119-06DCBF492C3F}"
!define INSTALL_KEY_US_WIN32 "SOFTWAREMicrosoftWindowsCurrentVersionUninstallInstallShield_{BFA90209-7AFF-4DB6-8E4B-E57305751AD7}"
!define INSTALL_KEY_UNK164 "SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstallInstallShield_{C019D439-E7F8-49EB-85FA-6D0C8CCBDA23}"
!define INSTALL_KEY_UNK264 "SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstallInstallShield_{A007C579-B78D-4FDE-A85A-16987A251E53}"
!define INSTALL_KEY_UNK364 "SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstallInstallShield_{FDBBAF14-5ED8-49B7-A5BE-1C35668B074D}"
!define INSTALL_KEY_UNK464 "SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstallInstallShield_{69082C6E-1944-4EAD-B119-06DCBF492C3F}"
!define INSTALL_KEY_US_WIN64 "SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstallInstallShield_{BFA90209-7AFF-4DB6-8E4B-E57305751AD7}"

Section "MainSection" SEC01
	SetOutPath $INSTDIR

	ReadRegStr $0 HKCU "${INSTALL_KEY_UNK132}" 'InstallLocation'
    IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK232}" 'InstallLocation'
    IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK332}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK432}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_US_WIN32}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK164}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK264}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK364}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_UNK464}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
		ReadRegStr $0 HKCU "${INSTALL_KEY_US_WIN64}" 'InstallLocation'
	IfErrors 0 CreateShortcuts
	    GOTO SkipShortcuts

    CreateShortcuts:
	  	IffileExists "$0BinariesUT3.exe" 0 SkipShortcuts
	        MessageBox MB_OK "$0BinariesUT3.exe"
	    GOTO Done

    SkipShortcuts:
    	MessageBox MB_OK "The Shortcuts have not been created."

	Done:
SectionEnd
  • I think there maybe 2 problems with your script.
    1) Say for example if it does not find the registry key in HKCU “${INSTALL_KEY_UNK132}” a error flag is then set. The next line then checks for this flag and if true. continue to the next line and so on. The problem here is if the flag is set in the 1st line, it will allways keep checking and wont go on to CreateShortcuts.
    A simple “ClearErrors” on the next line after each “IfErrors” line would do it.

    2) What if the current user running your install is not the same user that installed UT3? The registry for HKCU will not have any of those keys you are currently searching for. So at that point I would suggest adding the following

    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREMicrosoftWindowsCurrentVersionUninstall{BFA90209-7AFF-4DB6-8E4B-E57305751AD7}” “InstallLocation”
    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall{BFA90209-7AFF-4DB6-8E4B-E57305751AD7}” “InstallLocation”

    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREMicrosoftWindowsCurrentVersionUninstall{C019D439-E7F8-49EB-85FA-6D0C8CCBDA23}” “InstallLocation”
    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall{C019D439-E7F8-49EB-85FA-6D0C8CCBDA23}” “InstallLocation”

    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREMicrosoftWindowsCurrentVersionUninstall{A007C579-B78D-4FDE-A85A-16987A251E53}” “InstallLocation”
    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall{A007C579-B78D-4FDE-A85A-16987A251E53}” “InstallLocation”

    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREMicrosoftWindowsCurrentVersionUninstall{FDBBAF14-5ED8-49B7-A5BE-1C35668B074D}” “InstallLocation”
    ReadRegStr $0 HKEY_LOCAL_MACHINE “SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall{FDBBAF14-5ED8-49B7-A5BE-1C35668B074D}” “InstallLocation”

    • Bob

      You are completely correct on both counts, except that i wasnt meaning for that script to be the end all be all for the installer script and have updated mine to include the ClearErrors. You can see it on my SVN for more on how i actually went through it.

      As for the second there is a bit of a catch 22 there, as not all of those key locations are able to be located either. I actually began working with those and was turned to the HKCU by the mailing list.

      Testing will certainly come to help sort out these issues, and i thank you for the commentary/suggestions. =)

  • Bob
  • Bob

    I have updated my scripts to include the paths you commented in. Thank you for the suggestion