Skip to content
⌘ NSIS Forum Archive

How to System.dll call plugin GetBinaryTypeA

3 posts

PascalB#

How to System.dll call plugin GetBinaryTypeA

Hi folks,

i have to check, if a application binary is 32 or 64 bit inside a Section.
Depending on the return value i have to execute different MSI-packages.

Windows has a nice function GetBinaryTypeA but i don't know how to set the parameters in NSIS syntax.

Here is what i have:

; Set output path to the windows\system32 directory.
SetOutPath $WINDIR\System32 ; Set Path to kernel32.dll

StrCpy $0 "C:\Program Files\Microsoft Office\root\Office16\winword.exe" ; assign memory to $0
System::Call 'Kernel32::GetBinaryTypeA(t, *i) i(.r0, r1r1).r2'
DetailPrint 'Path: "$0"'
DetailPrint "Path length: $1"
DetailPrint "Return value: $2"
I only need the integer returned by the function. But i do always get $2 = 0, even if i use a invalid filename 😕

$0 is always empty and $1 is always a 6 digit number.


Thanks in advance!
Best regards,
Pascal
Anders#
You are pretty close but "GetBinaryTypeA" should be "GetBinaryType" for compatibility with Unicode and ".r0" is wrong, it means write to $0, you want "r0" (read from $0).

StrCpy $0 "$windir\Explorer.exe"
System::Call 'KERNEL32::GetBinaryType(tr0, *i.r1)i.r0'
DetailPrint "Function returned $0, type is $1"
...
or

System::Call 'KERNEL32::GetBinaryType(ts, *i.r1)i.r0' "$windir\Explorer.exe"
DetailPrint "Function returned $0, type is $1"
${If} $0 <> 0
... $1
${EndIf}
You should use $SysDir, not $WinDir\system32.

Your detection is probably flawed if Office 64 installs to the real 64-bit program files folder. Use the macros in x64.nsh to disable the FS redirection around the call to GetBinaryType.