Is it possible using AHK script to determine whether the file (exe or dll) is x64 or x86?
Please give me advise howto?
is exe file x64 or x86? Howto? Topic is solved
is exe file x64 or x86? Howto?
It's impossible to lead us astray for we don't care even to choose the way.
Re: is exe file x64 or x86? Howto? Topic is solved
msdn wrote:Determines whether a file is an executable (.exe) file, and if so, which subsystem runs the executable file.
Code: Select all
MsgBox % GetBinaryType("C:\Windows\System32\calc.exe") ; -> 32BIT
GetBinaryType(Application)
{
static Type := {0 : "32BIT", 1: "DOS", 2: "WOW", 3: "PIF", 4: "POSIX", 5: "OS216", 6: "64BIT"}
DllCall("GetBinaryType", "str", Application, "uint*", BinaryType)
return Type[BinaryType]
}
GetBinaryType function (msdn)
To check if a .dll is 32 or 64-Bit you can try to load the .dll with LoadLibrary
Ref:
LoadLibrary function (msdn)
Or read the file header:
32-Bit: PE L
64-Bit: PE d†
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: is exe file x64 or x86? Howto?
2jNizM
It is great! Thank you so much!
Do I understand correctly - this is a Windows function call?
It is great! Thank you so much!
Do I understand correctly - this is a Windows function call?
It's impossible to lead us astray for we don't care even to choose the way.
Re: is exe file x64 or x86? Howto?
Yes. GetBinaryType is a Kernel32.dll function
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: is exe file x64 or x86? Howto?
2jNizM
Unicode version of AHK requires call of GetBinaryTypeW
BTW, Thank you again
Unicode version of AHK requires call of GetBinaryTypeW
BTW, Thank you again
It's impossible to lead us astray for we don't care even to choose the way.
Re: is exe file x64 or x86? Howto?
I'm using AHK 1.1.24.4 in Windows 7 Pro x64 and I'm a bit confused. In the code below, both of the first two supposedly 64-bit exes show as 32-bit and I don't understand why. I thought at first that it was because I have the 32-bit Unicode version of AHK installed. To test this I installed the 64-bit version of AHK 1.1.24.5 (i.e. the latest) in a new Windows 7 Pro x64 VM and ran the code.
Both MsgBox's showed 32BIT... yet Calibre isn't even installed.
So I added a 3rd MsgBox pointing at a fictitious executable. When I run the code it shows 3 MsgBox's, all showing 32BIT.
Both MsgBox's showed 32BIT... yet Calibre isn't even installed.
So I added a 3rd MsgBox pointing at a fictitious executable. When I run the code it shows 3 MsgBox's, all showing 32BIT.
Code: Select all
MsgBox % GetBinaryType("C:\Program Files\AutoHotkey\AutoHotkeyU64.exe") ; Shows as 32BIT
MsgBox % GetBinaryType("C:\Program Files\Calibre2\calibre.exe") ; Shows as 32BIT, even when not installed
MsgBox % GetBinaryType("C:\This\is a\fictitious\filepath.exe") ; Shows as 32BIT despite filepath not existing
GetBinaryType(Application)
{
static Type := {0 : "32BIT", 1: "DOS", 2: "WOW", 3: "PIF", 4: "POSIX", 5: "OS216", 6: "64BIT"}
DllCall("GetBinaryType", "str", Application, "uint*", BinaryType)
return Type[BinaryType]
}
Re: is exe file x64 or x86? Howto?
Hmmm... I've just seen Ovg's last post and changed the DllCall in line 8 as follows:
The first 2 MsgBox's now display as I would expect (hope), i.e. 64BIT... but the third still shows 32BIT, even though it's a fictitious filepath. This means that if you make a typo in the filepath and don't spot it then you'll assume that whatever you're checking is 32-bit. I don't understand why there's not an error.
Code: Select all
MsgBox % GetBinaryType("C:\Program Files\AutoHotkey\AutoHotkeyU64.exe") ; Shows as 32BIT
MsgBox % GetBinaryType("C:\Program Files\Calibre2\calibre.exe") ; Shows as 32BIT
MsgBox % GetBinaryType("C:\This\is a\fictitious\filepath.exe") ; Shows as 32BIT
GetBinaryType(Application)
{
static Type := {0 : "32BIT", 1: "DOS", 2: "WOW", 3: "PIF", 4: "POSIX", 5: "OS216", 6: "64BIT"}
DllCall("GetBinaryTypeW", "str", Application, "uint*", BinaryType)
return Type[BinaryType]
}
Re: is exe file x64 or x86? Howto?
2RickC
MSDN wrote:
".... If the file is not executable, or if the function fails, the return value is zero.
To get extended error information, call GetLastError."
We need to check value returned by the DLLCall
MSDN - jNizM's link
MSDN wrote:
".... If the file is not executable, or if the function fails, the return value is zero.
To get extended error information, call GetLastError."
We need to check value returned by the DLLCall
MSDN - jNizM's link
It's impossible to lead us astray for we don't care even to choose the way.
Re: is exe file x64 or x86? Howto?
Sorry my mystake
Code: Select all
MsgBox % GetBinaryType("C:\Windows\System32\notepad.exe") ; -> 64BIT
MsgBox % GetBinaryType("C:\Windows\SysWOW64\notepad.exe") ; -> 32BIT
MsgBox % GetBinaryType("C:\Temp\ThisFileDoesNotExist.exe") ; -> 0
GetBinaryType(Application)
{
static GetBinaryType := "GetBinaryType" (A_IsUnicode ? "W" : "A")
static Type := {0 : "32BIT", 1: "DOS", 2: "WOW", 3: "PIF", 4: "POSIX", 5: "OS216", 6: "64BIT"}
if !(DllCall(GetBinaryType, "str", Application, "uint*", BinaryType))
return 0
return Type[BinaryType]
}
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: is exe file x64 or x86? Howto?
Thank you Ovg for the explanation; thank you jNizM for the MSDN link and revised example... it was all very helpful.
Re: is exe file x64 or x86? Howto?
2jNizM
Thank you so much for examples, links and clarifications!
I really appreciate your help!
Thank you so much for examples, links and clarifications!
I really appreciate your help!
It's impossible to lead us astray for we don't care even to choose the way.