Archive: GetWinVersion


GetWinVersion


Function .onInit

Call GetWindowsVersion
Pop $R0
StrCmp $R0 "XP" +1 +3
!define WINNT
Goto inst
StrCmp $R0 "2000" +1 +5
!ifndef WINNT
!define WINNT
!endif
Goto inst
StrCmp $R0 "2003" +1 +5
!ifndef WINNT
!define WINNT
!endif
Goto inst
!define WIN9X
inst:
FunctionEnd

SubSection /e "For Win2k or WinXP"
!ifdef WINNT
Section "Russian" Section1
!else
Section /o "Russian" Section1
!endif
.....

SubSection /e "For Win98 or WinME"
!ifndef WINNT
Section "Russian" Section1
!else
Section /o "Russian" Section1
!endif

On Windows XP work Ok, but if I run on Win98 not working.
How I can change default section in runtime
My Sections:

+For Win2k and WinXP
-Russian
-English
+For Win98 and WinMe
-Russian
-English

I copied the function:

;==========================================================================
; GetWindowsVersion
;==========================================================================
; GetWindowsVersion
;
; Based on Yazno's function, http://yazno.***********/powerpimpit/
; Updated by Joost Verburg
;
; Returns on top of stack
;
; Windows Version (95, 98, ME, NT x.x, 2000, XP, 2003)
; or
; '' (Unknown Windows Version)
;
; Usage:
; Call GetWindowsVersion
; Pop $R0
; ; at this point $R0 is "NT 4.0" or whatnot
Function GetWindowsVersion

Push $R0
Push $R1

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

Pop $R1
Exch $R0

FunctionEnd

which works perfect on all win versions...

StrCmp "$WINDOWS_VERSION" '95' doWin_95
StrCmp "$WINDOWS_VERSION" '98' doWin_98
StrCmp "$WINDOWS_VERSION" 'ME' doWin_ME
StrCmp "$WINDOWS_VERSION" 'NT' doWin_NT
StrCmp "$WINDOWS_VERSION" '2000' doWin_2K
StrCmp "$WINDOWS_VERSION" 'XP' doWin_XP


You are mixing up compile-time and run-time. Defines are processed on compile-time. The version check is a run-time action, you should therefore use a variable to set whether NT is used or not.

Checking for the existance of the Windows version in the Windows NT registry key is also a better method.


I replaced to code:


StrCmp $R0 "XP" doWinNT
StrCmp $R0 "2000" doWinNT
StrCmp $R0 "2003" doWinNT
!define WIN9X

Goto inst

doWinNT:
!define WINNT
Goto inst

inst:

but Section not set.
I want say, that version detect correctly, and Default section not work.

Again, defines are compile-time operations, use variables instead.


Originally posted by Joost Verburg
Again, defines are compile-time operations, use variables instead.
How? I don't undetstand how I can do this?

But I solved with SetCurInstType 1 or 0