Type
TExeType = (etUnknown, etDOS, etWinNE, etWinPE);
const
ExeStrings: array[TExeType] of string =
('Bilinmiyor', 'Dos', '16BitWin', '32BitWin');
function GetExeType(const FileName: string): TExeType;
var
Signature,
WinHdrOffset: Word;
fexe: TFileStream;
begin
Result := etUnknown;
try
fexe := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
try
fexe.ReadBuffer(Signature, SizeOf(Signature));
if Signature = $5A4D { 'MZ' } then
begin
Result := etDOS;
fexe.Seek($18, soFromBeginning);
fexe.ReadBuffer(WinHdrOffset, SizeOf(WinHdrOffset));
if WinHdrOffset >= $40 then
begin
fexe.Seek($3C, soFromBeginning);
fexe.ReadBuffer(WinHdrOffset, SizeOf(WinHdrOffset));
fexe.Seek(WinHdrOffset, soFrombeginning);
fexe.ReadBuffer(Signature, SizeOf(Signature));
if Signature = $454E { 'NE' } then
Result := etWinNE
else
if Signature = $4550 { 'PE' } then
Result := etWinPE;
end;
end;
finally
fexe.Free;
end;
except
end;
end;
// Kullanimi:
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := ExeStrings[GetExeType('C:\windows\notepad.exe')];
end;