View Single Post
Old 10th April 2015, 17:32   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,195
There might be something strange with the version info in that .exe after all!

Quote:
Outfile "$%Temp%\Test.exe"
Unicode false
RequestExecutionLevel user

!include LogicLib.nsh

Function GetFileVerFirstLangProductVersion
... http://pastebin.com/f5e461c4d
FunctionEnd


!define THEFILE "$Temp\X\vcredist_x86.exe" #"$windir\explorer.exe"

Section

!if "${NSIS_CHAR_SIZE}" <= 1
!addplugindir "$%Temp%\X\MoreInfo\Plugins\Ansi"
MoreInfo::GetProductName "${THEFILE}"
Pop $0
DetailPrint |$0|
!endif

Push "${THEFILE}"
Call GetFileVerFirstLangProductVersion
Pop $0
DetailPrint |$0|

SectionEnd
This fails to read correctly when compiling as Ansi but works correctly when compiled as Unicode! Reading the version info from %windir%\explorer.exe works in both.

I'm not sure if VerQueryValueA is broken or if the .exe is not following the PE spec. Either way, this bug is not in NSIS...

You can work around it like this:
Quote:
Function GetFileVerFirstNamedLangEntryOnWindowsNT
System::Store S
pop $3
pop $4
push "" ;failed ret
System::Call 'version::GetFileVersionInfoSizeW(w"$3",i.r2)i.r0'
${If} $0 <> 0
System::Alloc $0
System::Call 'version::GetFileVersionInfoW(w"$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::VerQueryValueW(i r1,w "\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::VerQueryValueW(i r1,w "\StringFileInfo\$2$3\$4",*i0r2,*i0r3)i.r0'
${If} $0 <> 0
pop $0
System::Call *$2(&w$3.s)
${EndIf}
${EndIf}
${EndIf}
System::Free $1
${EndIf}
System::Store L
FunctionEnd

Section
Push LegalCopyright
Push "${THEFILE}"
Call GetFileVerFirstNamedLangEntryOnWindowsNT
Pop $0
DetailPrint |$0|

Push FileDescription
Push "${THEFILE}"
Call GetFileVerFirstNamedLangEntryOnWindowsNT
Pop $0
DetailPrint |$0|
SectionEnd
...will not work on Win9x and is probably not a good idea in general, it would be better if we could figure out why the Ansi version fails...

If someone has a VM with Win95/98 it would be fun to see what Windows does there...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote