Archive: GetWindowsVersion does not work!


GetWindowsVersion does not work!
I added this to my NSIS script:

Call GetWindowsVersion
Pop $R0

When I ran the script I got the following error:

Error: command Call not valid outside Section or Function
Error in script "C:\aasource\32 bit apps\7.3 trunk\client install\Install Script.nsi" on line 22 -- aborting creation process

Not sure what to do. I have JUST begun using NSIS.


Just as the error says, you can't call functions from outside a function or section.

Place your code inside a section or function.


I put it inside a section and it said I couldn't use INSTDIR inside a section! If I put it inside a function don't I still need to use CALL to call the function?

Help!


I was getting errors from this:

;Default installation folder
; RGM 20080606 check for Vista first
Section "Install Path"
Call GetWindowsVersion
Pop $R0
SectionEnd

${If} $R0 == "Vista"
InstallDir "blah"
${Else}
InstallDir "blah"
${EndIf}


Call can only be used inside a function/section, whereas InstallDir can only be used outside a function/section.

If you want to set $INSTDIR from within a section or function, just set it using StrCpy to set.

BTW: You say you want to set the default install directory, but you are doing this within a section. It'd probably be better to do this in the .onInit function so that it's set BEFORE you display the directory page to the user.

Example:


Function .onInit
"Install Path"
Call GetWindowsVersion
Pop $R0

${If} $R0 == "Vista"
StrCpy $INSTDIR "blah"
${Else}
StrCpy $INSTDIR "other blah"
${EndIf}
FunctionEnd

With that code I get:

Error: resolving install function "GetWindowsVersion" in function ".onInit"


I removed "Install Path" from your code by the way, since it created an error.

Also I added a Call .onInit before the function to see if that worked, but to no avail.

Different world this NSIS!


You need to put the entire GetWindowsVersion function in your script as well.

Stu


:-o


I get the same error. Here is my code now:

Function GetWindowsVersion

Push $R0
Push $R1

ClearErrors

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 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_error:
Strcpy $R0 ''
lbl_done:

Pop $R1
Exch $R0

FunctionEnd

Function .onInit
Call GetWindowsVersion
Pop $R0

${If} $R0 == "Vista"
StrCpy $INSTDIR "blah"
${Else}
StrCpy $INSTDIR "other blah"
${EndIf}
FunctionEnd


Why are you not using WinVer.nsh?


I included that and still get this message:

Error: resolving install function "GetWindowsVersion" in function ".onInit"


Try this.

At the top of your script, you need:


!include WinVer.nsh


Then, simplifying .onInit:
(Note: I put the message boxes in the code just so that you can test and see that it's giving you the right results. Remove them for the "production" code.)

Function .onInit
${If} ${IsVista}
StrCpy $INSTDIR "blah"
MessageBox MB_OK "VISTA"
${Else}
StrCpy $INSTDIR "other blah"
MessageBox MB_OK "Something else"
${EndIf}
FunctionEnd

I feel quite embarrassed. It is now working. Thanks!