来自 exe 的产品版本字符串 - nsis [英] Product version string from an exe - nsis

查看:33
本文介绍了来自 exe 的产品版本字符串 - nsis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从给定的可执行文件(实际上是从安装程序)读取产品版本(可选字符串)如果在运行时可能的话,我正在尝试创建它是否有任何区别).此字符串将进一步用于从链接下载文件.

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.

非常感谢!

推荐答案

NSIS 没有对阅读除 VS_FIXEDFILEINFO->dwFileVersion 所以你必须调用 Windows直接API:

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

这篇关于来自 exe 的产品版本字符串 - nsis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆