来自 exe 的产品版本字符串 - nsis

Product version string from an exe - nsis

我想从给定的可执行文件中读取产品版本 (optional string)(实际上是从我尝试创建的安装程序中读取,如果它有任何不同的话),如果可以的话 运行-时间。该字符串将进一步用于从 link.

下载文件

非常感谢!

NSIS 本机不支持读取 VS_FIXEDFILEINFO->dwFileVersion 以外的任何内容,因此您必须直接调用 Windows API:

; 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 
push "" ;failed ret
System::Call 'version::GetFileVersionInfoSize(t"",i.r2)i.r0'
${If} [=10=] <> 0
    System::Alloc [=10=]
    System::Call 'version::GetFileVersionInfo(t"",ir2,ir0,isr1)i.r0 ? e'
    pop 
    ${If} [=10=] <> 0
    ${AndIf}  = 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} [=10=] <> 0
            System::Call '*(&i2.r2,&i2.r3)'
            IntFmt  %04x 
            IntFmt  %04x 
            System::Call 'version::VerQueryValue(i r1,t "\StringFileInfo$2\ProductVersion",*i0r2,*i0r3)i.r0'
            ${If} [=10=] <> 0
                pop [=10=]
                System::Call *(&t.s)
            ${EndIf}
        ${EndIf}
    ${EndIf}
    System::Free 
${EndIf}
System::Store L
FunctionEnd

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