0
votes

I want to read the product version (optional string) from a given executable (actually from the installer I'm trying to create if it makes any difference), if it is possible at the run-time. This string will be further used to download files from a link.

Thank you very much !

1
@Anders, the output of that function is DetailPrint: "ProdVer: $R2.$R3.$R4.$R5" .... and I need the actual values... - gigiman
It works just fine for me but it gets the value at run-time and that is what you asked for ("keep it into a variable"). If you wanted it in a define at compile time then you should have asked for that... - Anders
@Anders , please forgive my lack of knowledge. I just want to use the installer's product version name (it is really just a name, not a something like xx.xx.xx.xx or whatever) in order to access a link for downloading some files needed for exactly that product version. I don't know any approach, and I thought about storing it in a var . Could you please tell me what are my choices or give me a valid example? - gigiman
I already pointed you to something that gives you exactly what you asked for, getdllversion for the 64-bit product version stored in the fixed block in the version info. - Anders
@Anders , I do not know how to use it then...btw I'm using 32-bit system. - gigiman

1 Answers

2
votes

NSIS does not have native support for reading anything other than VS_FIXEDFILEINFO->dwFileVersion so you have to call the Windows API directly:

; Add some version information so we have something to test
VIProductVersion 1.2.3.4
VIAddVersionKey "ProductVersion" "One Two Three Four"
VIAddVersionKey "FileVersion" "Whatever"
VIAddVersionKey "FileDescription" "Whatever"
VIAddVersionKey "LegalCopyright" "(C) Whatever"

!include LogicLib.nsh
Function GetFileVerFirstLangProductVersion
System::Store S
pop $3
push "" ;failed ret
System::Call 'version::GetFileVersionInfoSize(t"$3",i.r2)i.r0'
${If} $0 <> 0
    System::Alloc $0
    System::Call 'version::GetFileVersionInfo(t"$3",ir2,ir0,isr1)i.r0 ? e'
    pop $2
    ${If} $0 <> 0
    ${AndIf} $2 = 0 ;a user comment on MSDN said you should check GLE to avoid crash
        System::Call 'version::VerQueryValue(i r1,t "\VarFileInfo\Translation",*i0r2,*i0)i.r0'
        ${If} $0 <> 0
            System::Call '*$2(&i2.r2,&i2.r3)'
            IntFmt $2 %04x $2
            IntFmt $3 %04x $3
            System::Call 'version::VerQueryValue(i r1,t "\StringFileInfo\$2$3\ProductVersion",*i0r2,*i0r3)i.r0'
            ${If} $0 <> 0
                pop $0
                System::Call *$2(&t$3.s)
            ${EndIf}
        ${EndIf}
    ${EndIf}
    System::Free $1
${EndIf}
System::Store L
FunctionEnd

Section
Push "$ExePath" ; Read our own version information in this example
Call GetFileVerFirstLangProductVersion
Pop $0
DetailPrint "ProductVersion=$0"
SectionEnd