Jump to content
Sign in to follow this  

How to tell if a EXE or DLL is x64 or x86.....

Recommended Posts


I found the thread "Check if EXE is x64?" at Neowin forums and decided to see if I could translate the code into AutoIt..... Here's the new function for all to use!

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
MsgBox(0, "", _File_Is_X64("C:\Windows\system32\calc.exe"))
MsgBox(0, "", _File_Is_X64("C:\Windows\SysWOW64\wscript.exe"))
MsgBox(0, "", _File_Is_X64("C:\Windows\System32\shell32.dll"))
MsgBox(0, "", _File_Is_X64("C:\Windows\SysWOW64\shell32.dll"))

Func _File_Is_X64($file)
Local $handle = FileOpen($file, 16)
If $handle = -1 Then Return SetError(-2, -2, "Invalid")
If BinaryToString(FileRead($handle, 2)) = 'MZ' Then
FileSetPos($handle, 60, 0)
FileSetPos($handle, Int(FileRead($handle, 4)) + 4, 0)
Local $in = FileRead($handle, 2)
If $in = "0x6486" Then Return "AMD64"
If $in = "0x4c01" Then Return "i386"
If $in = "0x0002" Then Return "IA64"
Return "Unknown"
EndFunc ;==>_File_Is_X64

Note that if you are checking a file in the system32 folder and running the Autoit script as a 32-bit application, it will always report "i386" because of the 64-bit OS's redirection mechanism that sends those requests to the SysWOW64 folder.

Hope this helps somebody!


Edited by Dougiefresh

Share this post

Link to post
Share on other sites


Just curious, have you checked out:

http://msdn.microsoft.com/en-us/library/aa364819%28VS.85%29.aspx which the link above the reference post you provided also noted

If you looked at:

You could have possibly used:


Which you can probably find references on use here:



Played around with yours a bit, I noticed you only close the handle if a successful PE header.

I didn't thoroughly test this, but might give you different perspective, since you're function says you're testing for x64, I was unsure why you returning strings, so I included the types in the @extended portion:

Func _PE_Isx64($s_pe)
    ; extended: 1 = amd64, 2 = ia64, 4 = i386

    Local $h_pe = FileOpen($s_pe, 16)
    If $h_pe = -1 Then Return SetError(1, 0, 0)

    If BinaryToString(FileRead($h_pe, 2)) <> "MZ" Then
        Return SetError(2, 0, 0)

    FileSetPos($h_pe, 60, 0)

    Local $sz_type = FileRead($h_pe, 4)
    FileSetPos($h_pe, Number($sz_type) + 4, 0)

    $sz_type = FileRead($h_pe, 2)
    Switch $sz_type
        Case "0x6486"
            Return SetExtended(1, 1)
        Case "0x0002"
            Return SetExtended(2, 1)
        Case "0x4C01"
            Return SetExtended(4, 0)

    Return SetError(3, 0, 0)
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this