Search code examples
javaiconsexensisfile-association

Can't change .exe-icon for specific OutPut .exe-name (NSIS)


I'm running Windows 8.1 and using NSIS to create a launcher for my java program. To try the scripting out, I just made an ugly A.ico and used it for my Program.exe. Now I've made a pretty B.ico and using the same script I'm trying to set this to be the icon of my Program.exe.

The thing is that even though I change the script accordingly, the A.ico is still used for Program.exe, and I can't seem to change that. It's SUPER weird, because if I change the name of the output .exe to e.g. OtherProgram.exe the correct B.ico is chosen. If I then rename the .exe back to Program.exe, the icon switches back to A.ico in front of my eyes!!

Have I missed something? Has my system saved that every file named Program.exe must have the icon A.icon, just because I used that in my first script?

Name "Program"
Caption "LMX Launcher"
Icon "hidden\B.ico"
OutFile "Program.exe"

RequestExecutionLevel user

!include "FileAssociation.nsh"

SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow

Section ""
  Call GetJRE
  Pop $R0
  StrCpy $0 '$R0 -jar hidden\getdown.jar hidden\'
  SetOutPath $EXEDIR
  ExecWait $0
  ${unregisterExtension} ".lm" "LM-fil"
  ${registerExtension} "Program.exe" ".lm" "LM-fil"
SectionEnd

Function GetJRE
  Push $R0
  Push $R1

  ClearErrors
  StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
  IfFileExists $R0 JreFound
  StrCpy $R0 ""

  ClearErrors
  ReadEnvStr $R0 "JAVA_HOME"
  StrCpy $R0 "$R0\bin\javaw.exe"
  IfErrors 0 JreFound

  ClearErrors
  ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
  ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
  StrCpy $R0 "$R0\bin\javaw.exe"

  IfErrors 0 JreFound
  StrCpy $R0 "javaw.exe"

 JreFound:
  Pop $R1
  Exch $R0
FunctionEnd

Solution

  • Sounds like a Windows icon cache issue, rather than an NSIS problem. You can empty the cache using the following command:

    ie4uinit.exe -ClearIconCache