Search code examples
registrynsisaddremoveprograms

Create entry in Add/Remove programs through NSIS,why are registry keys not added?


I am using NSIS to create an installer/uninstaller for my application. I want to create an entry in the Add/Remove Programs list in the Control Panel. I went through the steps on the NSIS wiki: https://nsis.sourceforge.io/Add_uninstall_information_to_Add/Remove_Programs

But also found that apparently we need to set the registry for 64-bit view. So I ended up with the following code:

Section "" 

SetOutPath $INSTDIR
File /r  appfiles\

${If} ${RunningX64} 
  SetRegView 64
${Else}
  SetRegView 32
${Endif}
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Aplicacion" "DisplayName" 
"Desinstalar Aplicación"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Aplicacion" 
"UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Aplicacion" "DisplayIcon" 
"$\"$INSTDIR\appfiles\Resources\logo.jfif$\""

WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Aplicacion" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Aplicacion" "NoRepair" 1
SetRegView lastused
WriteUninstaller "$INSTDIR\uninstall.exe"  

SectionEnd

However, after running the installer, and checking the appropiate registry section with regedit.exe, I find that nothing was written to the registry under these keys. What am I missing or doing incorrectly?


Solution

  • Only use SetRegView if you are installing a 64-bit application, and even then it is not strictly required.

    You are probably just looking in the wrong place in Regedit. A 32-bit application on 64-bit Windows will write its values to HKLM\Software\Wow6432Node... by default.

    The Settings app checks both the 32-bit and 64-bit key for uninstall information.

    You should also have RequestExecutionLevel Admin in your .nsi so you can write to HKLM.