Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active January 13, 2020 19:14
Show Gist options
  • Save TLMcode/b6ce2f3209808ea6f8dad76f5a9c79d8 to your computer and use it in GitHub Desktop.
Save TLMcode/b6ce2f3209808ea6f8dad76f5a9c79d8 to your computer and use it in GitHub Desktop.
Determines whether a file is an executable (.exe) file, and if so, which subsystem runs the executable file.
path := A_ScriptDir "\curl.exe" ; example path to executable
Msgbox % GetBinaryType( path ) ; example call
GetBinaryType( bin, warn:=0 )
{
typeConsts := [ "32BIT_BINARY", "DOS_BINARY", "WOW_BINARY", "PIF_BINARY"
, "POSIX_BINARY", "OS216_BINARY", "64BIT_BINARY" ]
VarSetCapacity( type, 4 )
if !DllCall( "GetBinaryType" ( A_IsUnicode ? "W": "A" ), Str, bin, Ptr, &type )
{
if ( warn = 1 )
MsgBox, 0x30, Error!, The specified file is not an executable.
Return 0
}
Return "SCS_" . typeConsts[ NumGet(&type)+1 ]
}
/*
GetBinaryType( bin, warn:=0 ) [Ansi/Unicode] bit.ly/GetBinaryType_MSDN
Description: Determines whether a file is an executable (.exe) file,
and if so, which subsystem runs the executable file.
Parameters:
bin: The full path of the file whose executable type is to be determined.
warn (optional): Displays a message if the executable is invalid.
Return value: If the file is executable, the return value is a nonzero constant.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment