Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to determine the type of an EXE file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Sep-02
Category
Files Operation
Language
Delphi All Versions
Views
102
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

Determine the type of an EXE file

Answer:

Here's a function to return the platform the executable was designed for (16/32 bit 
Windows or DOS). Read the comment for the usage. This function works as well with 
DLLs, COMs, and maybe others. Thanks to Peter Below for this code.

Use it as shown at the bottom of the code snippet. 
1   
2   //-------------------------------------------------------------------------
3   //  function to return the type of executable or dll (DOS, 16-bit, 32-bit).
4   //-------------------------------------------------------------------------
5   
6   type
7     TExeType = (etUnknown, etDOS, etWinNE {16-bit}, etWinPE {32-bit});
8   
9   function GetExeType(const FileName: string): TExeType;
10  var
11    Signature,
12      WinHdrOffset: Word;
13    fexe: TFileStream;
14  begin
15    Result := etUnknown;
16    try
17      fexe := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
18      try
19        fexe.ReadBuffer(Signature, SizeOf(Signature));
20        if Signature = $5A4D { 'MZ' } then
21        begin
22          Result := etDOS;
23          fexe.Seek($18, soFromBeginning);
24          fexe.ReadBuffer(WinHdrOffset, SizeOf(WinHdrOffset));
25          if WinHdrOffset >= $40 then
26          begin
27            fexe.Seek($3C, soFromBeginning);
28            fexe.ReadBuffer(WinHdrOffset, SizeOf(WinHdrOffset));
29            fexe.Seek(WinHdrOffset, soFrombeginning);
30            fexe.ReadBuffer(Signature, SizeOf(Signature));
31            if Signature = $454E { 'NE' } then
32              Result := etWinNE
33            else if Signature = $4550 { 'PE' } then
34              Result := etWinPE;
35          end;
36        end;
37      finally
38        fexe.Free;
39      end;
40    except
41    end;
42  end;
43  
44  begin
45    case GetExeType(aFileName) of
46      etUnknown: Label3.Caption := 'Unknown file type';
47      etDOS: Label3.Caption := 'DOS executable';
48      etWinNE: {16-bit} Label3.Caption := 'Windows 16-bit executable';
49      etWinPE: {32-bit} Label3.Caption := 'Windows 32-bit executable';
50    end;
51  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC