0
votes

I need to make some installation steps only if for certain versions of windows - say only if not 10. The script is used in the context of electron builder (19.55.1) How do I change my nsh script to achieve this? The code that was picked from nsis wiki to get the version is not helping. Need help in identifying what is wrong with the below piece of script. Better still, is there a simpler/more readable way of doing this? Looks like winver.nsh is not upto it when it comes to windows 10 (at least the nsis documentation does not claim it)

Below is my current script that simply fails to compile in electron builder.

!include LogicLib.nsh
!include x64.nsh

Function GetWindowsVersion

Push $R0
Push $R1

; check if Windows 10 family (CurrentMajorVersionNumber is new introduced in Windows 10)
ReadRegStr $R0 HKLM \
  "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentMajorVersionNumber

StrCmp $R0 '' 0 lbl_winnt

ClearErrors

; check if Windows NT family
ReadRegStr $R0 HKLM \
"SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion

IfErrors 0 lbl_winnt

; we are not NT
ReadRegStr $R0 HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber

StrCpy $R1 $R0 1
StrCmp $R1 '4' 0 lbl_error

StrCpy $R1 $R0 3

StrCmp $R1 '4.0' lbl_win32_95
StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98

lbl_win32_95:
  StrCpy $R0 '95'
Goto lbl_done

lbl_win32_98:
  StrCpy $R0 '98'
Goto lbl_done

lbl_win32_ME:
  StrCpy $R0 'ME'
Goto lbl_done

lbl_winnt:

StrCpy $R1 $R0 1

StrCmp $R1 '3' lbl_winnt_x
StrCmp $R1 '4' lbl_winnt_x

StrCpy $R1 $R0 3

StrCmp $R1 '5.0' lbl_winnt_2000
StrCmp $R1 '5.1' lbl_winnt_XP
StrCmp $R1 '5.2' lbl_winnt_2003
StrCmp $R1 '6.0' lbl_winnt_vista
StrCmp $R1 '6.1' lbl_winnt_7
StrCmp $R1 '6.2' lbl_winnt_8
StrCmp $R1 '6.3' lbl_winnt_81
;StrCmp $R1 '10' lbl_winnt_10_2016

StrCpy $R1 $R0 4

StrCmp $R1 '10.0' lbl_winnt_10
Goto lbl_error

lbl_winnt_x:
  StrCpy $R0 "NT $R0" 6
Goto lbl_done

lbl_winnt_2000:
  Strcpy $R0 '2000'
Goto lbl_done

lbl_winnt_XP:
  Strcpy $R0 'XP'
Goto lbl_done

lbl_winnt_2003:
  Strcpy $R0 '2003'
Goto lbl_done

lbl_winnt_vista:
  Strcpy $R0 'Vista'
Goto lbl_done

lbl_winnt_7:
  Strcpy $R0 '7'
Goto lbl_done

lbl_winnt_8:
  Strcpy $R0 '8'
Goto lbl_done

lbl_winnt_81:
  Strcpy $R0 '8.1'
Goto lbl_done

lbl_winnt_10:
  Strcpy $R0 '10.0'
Goto lbl_done

lbl_error:
  Strcpy $R0 ''
lbl_done:

Pop $R1
Exch $R0
FunctionEnd

!macro customInstall
${GetWindowsVersion} $R0
${IfNot} $R0 == 10
${If} ${RunningX64}
; Do something
${Else}
; Do something
${EndIf}
${EndIf}
!macroend
1
What's the error message? Windows 10 support was added to WinVer a while ago - idleberg
Thanks. I had not checked the documentation of Winver. That of nsis stated support only upto 8.1. Winver solves the problem. - Amruta

1 Answers

0
votes

I'm assuming you commented out the ;StrCmp $R1 '10' lbl_winnt_10_2016 line? Try adding the line back but change lbl_winnt_10_2016 to lbl_winnt_10.

To debug things you can add a MessageBox mb_ok "R0=$R0,R1=$R1" call in various places in that code and look at the values after StrCpy and see if they make sense when they are compared in StrCmp.

WinVer.nsh got Windows 10 support in NSIS v3.0b2 (2015).