Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Ist Anwendung 32 oder 64 Bit (https://www.delphipraxis.net/167227-ist-anwendung-32-oder-64-bit.html)

Luckie 19. Mär 2012 11:56

Ist Anwendung 32 oder 64 Bit
 
Ich bin ja seit einer Woche stolzer Besitzer eines vier kern 645-Bit Rechners und Windows 7 64-Bit. Jetzt hatte ich mir ein Programm runtergeladen ohne Installer und wollte es in den richtigen Ordner kopieren: "Program Files" oder "Program Files(x86)". Nur hatte ich das Problem, dass ich nicht wusste, ob es eine 32 oder 64 Bit Anwendung ist. OK, es stand nicht dabei, dass es eine 645 Bit Anwendung ist, also könnte man davon ausgehen, dass es sich um eine 32 Bit Anwendung handelt.

Aber ich wüsste gerne mit welcher API Funktion man herausfinden kann, ob eine fremde Anwendung 32 oder 64 Bit ist. Ich wollte mir da dann nämlich ein kleines Programm zu schreiben, mit dem ich herausfinden kann, ob ein anderes Programm eben 32 oder 64 Bit ist.

Daniel 19. Mär 2012 12:00

AW: Ist Anwendung 32 oder 64 Bit
 
MSDN-Library durchsuchenImageNtHeader ist wohl Dein Freund.

Siehe auch:
http://stackoverflow.com/questions/9...86-x64-or-ia64
und
http://stackoverflow.com/questions/4...32bit-or-64bit

//edit: In Deinem Beitrag verstecken sich ein paar 5en zuviel ;-)

Luckie 19. Mär 2012 12:02

AW: Ist Anwendung 32 oder 64 Bit
 
Danke.

Unsinn. Ich bin nur schon auf die Zukunft vorbereitet mit dem Rechner. ;)

himitsu 19. Mär 2012 12:53

AW: Ist Anwendung 32 oder 64 Bit
 
Oder einfach mal starten, in den Taskmanager schauen
und danach in den Programmeordner verschieben.

Luckie 19. Mär 2012 13:08

AW: Ist Anwendung 32 oder 64 Bit
 
@Himitsu: Hey, ich bin Programmierer. ;)

Aphton 19. Mär 2012 14:44

AW: Ist Anwendung 32 oder 64 Bit
 
Vlt. etwas füe die Code-Library

Delphi-Quellcode:
function IsExecutable32Bit(const lpExeFilename: String): Boolean;
const
  kb32 = 1024 * 32;
var
  Buffer : Array[0..kb32-1] of Byte; // warning: assuming both headers are in there!
  hFile  : DWord;
  bRead  : DWord;
  bToRead : DWord;
  pDos   : PImageDosHeader;
  pNt    : PImageNtHeaders;
begin
  Result := False;
  hFile := CreateFile(pChar(lpExeFilename), GENERIC_READ, FILE_SHARE_READ, NIL,
    OPEN_EXISTING, 0, 0);
  if hFile <> INVALID_HANDLE_VALUE then
    try
      bToRead := GetFileSize(hFile, NIL);
      if bToRead > kb32 then bToRead := kb32;
      if not ReadFile(hFile, Buffer, bToRead, bRead, NIL) then Exit;
      if bRead = bToRead then
      begin
        pDos := @Buffer[0];
        if pDos.e_magic = IMAGE_DOS_SIGNATURE then
        begin
          pNt := PImageNtHeaders(LongInt(pDos) + pDos._lfanew);
          if pNt.Signature = IMAGE_NT_SIGNATURE then
            Result := pNt.FileHeader.Machine and IMAGE_FILE_32BIT_MACHINE > 0;
        end; {
        else
          raise Exception.Create('File is not a valid executable.');
        }
      end;  {
        else
          raise Exception.Create('File is not an executable.');
        }
    finally
      CloseHandle(hFile);
    end;
end;

function IsExecutable64Bit(const lpExeFilename: String): Boolean;
// since as of now (march 2012), there only exist 32 and 64 bit executables,
// if its not the one, its assumably the other
begin
  Result := not IsExecutable32Bit(lpExeFilename);
end;

Luckie 19. Mär 2012 15:49

AW: Ist Anwendung 32 oder 64 Bit
 
Hmpf, wenn man es nicht sofort programmiert... :(

Iwo Asnet 19. Mär 2012 15:58

AW: Ist Anwendung 32 oder 64 Bit
 
Zitat:

Zitat von Aphton (Beitrag 1157370)
Vlt. etwas füe die Code-Library...

Pah, viel zu kompliziert :mrgreen:
Delphi-Quellcode:
Function Is32EXE (aFileName : String) : Boolean;
Begin
  Result := Pos('Program Files(x86)',aFilename)=0;
End;
:wall:

p80286 19. Mär 2012 16:02

AW: Ist Anwendung 32 oder 64 Bit
 
Und wenn aus irgendwelchen finsteren Quellen doch noch eine 16Bit echse auftaucht?????

Gruß
K-H

Luckie 19. Mär 2012 16:14

AW: Ist Anwendung 32 oder 64 Bit
 
Zitat:

Zitat von p80286 (Beitrag 1157386)
Und wenn aus irgendwelchen finsteren Quellen doch noch eine 16Bit echse auftaucht?????

Die laufen nicht unter 64 Bit, also stellt sich die Frage gar nicht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:50 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz