Search code examples
nsis

Copy file over conditionally


I am trying to do the following in my NSIS script. I do not know NSIS, and I was just handed down a task to tweak something. The idea: if this is window8 take some .exe files from a different location to deploy onto the target machine:

So I start with getting the version:

ReadRegStr $WINVER HKLM \
 "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion

in the list of files to install I do this:

;List of files to install
File file1.exe
File file2.exe

${If} StrCmp $WINVER '6.2'
  File .\otherlocationSource\file1.exe
  File .\otherlocationSource\file2.exe
${EndIf}

I'm getting an NSIS script compile error on the ${if}... line.

I'd appreciate any pointers as to what I'm doing wrong.


Solution

  • The ${If} macro uses StrCmp internally, the syntax is ${If} $WINVER == "6.2" but you really should use WinVer.nsh to do the version check. (You can grab the version values from SVN if your local copy does not support Win8)

    And for a version check like this, unless it is Win8 specific you should have logic similar to "if $major > 6 or ($major == 6 and $minor >= 2)" so it also works on Win9 etc