Autor Beitrag
del1312
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190



BeitragVerfasst: Mi 26.05.10 18:46 
Nabend Leute,

kann mir bitte einer helfen und sagen, wie ich per Abfrage rausbekomme ob der aktuelle Rechner nen 64 bzw 32 bit System ist? Schreib grad nen kleines Prog, was unter WinXP32, WinXP64 und Win764 laufen soll und dafür muss mein kl. Prog wissen, auf was für ne Kiste es läuft damit z. B. der richtige Programm-Order gefunden wird. Wie kann ich das das schnell abfragen? DANKE!

Moderiert von user profile iconGausi: Topic aus Off Topic verschoben am Mi 26.05.2010 um 19:19
Moderiert von user profile iconNarses: Überflüssige Zeilenumbrüche/Leerzeilen entfernt.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 26.05.10 18:50 
ich denke das hier kann dir weiterhelfen.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 26.05.10 18:52 
In managed Code über die 'Environment.Is64BitOperatingSystem' Funktion. In unmanaged Code über die 'IsWow64Process' Windows API Methode.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 26.05.10 20:29 
user profile icondel1312 hat folgendes geschrieben Zum zitierten Posting springen:
dafür muss mein kl. Prog wissen, auf was für ne Kiste es läuft damit z. B. der richtige Programm-Order
gefunden wird.
Wie man diese Pfade bekommt habe ich hier geschrieben:
www.delphi-forum.de/....php?p=605453#605453
fuba
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win7
D7 Ent.
BeitragVerfasst: So 01.08.10 15:50 
ich nutze immer diese function:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function IsWow64: Boolean;
type
  TIsWow64Process = function// Type of IsWow64Process API fn
    Handle: Windows.THandle; var Res: Windows.BOOL
  ): Windows.BOOL; stdcall;
var
  IsWow64Result: Windows.BOOL;      // Result from IsWow64Process
  IsWow64Process: TIsWow64Process;  // IsWow64Process fn reference
begin
  // Try to load required function from kernel32
  IsWow64Process := Windows.GetProcAddress(
    Windows.GetModuleHandle('kernel32'), 'IsWow64Process'
  );
  if Assigned(IsWow64Process) then
  begin
    // Function is implemented: call it
    if not IsWow64Process(
      Windows.GetCurrentProcess, IsWow64Result
    ) then
      raise SysUtils.Exception.Create('IsWow64: bad process handle');
    // Return result of function
    Result := IsWow64Result;
  end
  else
    // Function not implemented: can't be running on Wow64
    Result := False;
end;
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 01.08.10 21:39 
user profile iconfuba hat folgendes geschrieben Zum zitierten Posting springen:
ich nutze immer diese function:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function IsWow64: Boolean;
type
  TIsWow64Process = function// Type of IsWow64Process API fn
    Handle: Windows.THandle; var Res: Windows.BOOL
  ): Windows.BOOL; stdcall;
var
  IsWow64Result: Windows.BOOL;      // Result from IsWow64Process
  IsWow64Process: TIsWow64Process;  // IsWow64Process fn reference
begin
  // Try to load required function from kernel32
  IsWow64Process := Windows.GetProcAddress(
    Windows.GetModuleHandle('kernel32'), 'IsWow64Process'
  );
  if Assigned(IsWow64Process) then
  begin
    // Function is implemented: call it
    if not IsWow64Process(
      Windows.GetCurrentProcess, IsWow64Result
    ) then
      raise SysUtils.Exception.Create('IsWow64: bad process handle');
    // Return result of function
    Result := IsWow64Result;
  end
  else
    // Function not implemented: can't be running on Wow64
    Result := False;
end;


dürften wir die gleiche Quelle zitieren, dein Code ist exakt der gleiche wie der im Listing 31 aus meinem Link. ;)

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 05.08.10 20:19 
Ehm, wie soll diese Funktion denn bitte funktionieren? Die prüft ob der aktuelle Prozess ein 64-Bit Prozess ist, was nie so sein wird, da Delphi (noch) keine 64-Bit Programme kompilieren kann. Wird also IMMER False ergeben, auch auf 64-Bit Systemen.

Kennt jemand eine andere Methode um das herauszufinden?
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Do 05.08.10 20:22 
Tja, der vorhersehende Programmierer baut halt jetzt schonmal seinen Code so, dass er auch noch funtioniert, wenn Delphi auf x64 umstellt :mrgreen:

Imho sollte der Code oben aber zusätzlich eine Exception werfen, wenn die Funktion nicht implementiert ist. :)

lg,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 05.08.10 20:28 
user profile iconelundril hat folgendes geschrieben Zum zitierten Posting springen:
Die Funktion kann man Afaik auch mit einem 32-bit-Programm aufrufen. ;) Eventuell sogar auf nem 32-Bit-Rechner, nur ob was sinnvolles dabei rauskommt bleibt offen.

Nein. Sie ergibt in dieser Form immer False, egal auf welchem Betriebssystem, da GetCurrentProcess ein 32-Bit Programm ist.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 05.08.10 20:40 
user profile iconHendi48 hat folgendes geschrieben Zum zitierten Posting springen:
Ehm, wie soll diese Funktion denn bitte funktionieren? Die prüft ob der aktuelle Prozess ein 64-Bit Prozess ist
Falsch... :roll:

user profile iconHendi48 hat folgendes geschrieben Zum zitierten Posting springen:
da GetCurrentProcess ein 32-Bit Programm ist.
Darum geht es ja auch.

Die Funktion heißt IsWow64Process, nicht Is64BitProcess oder sowas...
Wow64 ist die Emulation für 32-Bit Programme unter 64-Bit Windows Systemen. Wenn also das Programm als Wow64 Prozess läuft, dann wird es gerade unter einem 64-Bit System emuliert ausgeführt.

Die Funktion macht also genau das was hier gefragt ist.

Für diesen Beitrag haben gedankt: Hidden
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 06.08.10 15:12 
Alternative:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
function GetNativeSystemInfo(var SystemInfo: TSystemInfo): Boolean;
type
  TGetNativeSystemInfo = procedure (var SystemInfo: TSystemInfo) stdcall;
var
  LibraryHandle: HMODULE;
  _GetNativeSystemInfo: TGetNativeSystemInfo;
begin
  Result := False;
  LibraryHandle := GetModuleHandle(kernel32);

  if LibraryHandle <> 0 then
  begin
    _GetNativeSystemInfo := GetProcAddress(LibraryHandle,'GetNativeSystemInfo');
    if Assigned(_GetNativeSystemInfo) then
    begin
      _GetNativeSystemInfo(SystemInfo);
      Result := True;
    end
    else
      GetSystemInfo(SystemInfo);
  end
  else
    GetSystemInfo(SystemInfo);
end;

function IsWindows64: Boolean;
var
  ASystemInfo: TSystemInfo;
const
  PROCESSOR_ARCHITECTURE_INTEL = 0;
  PROCESSOR_ARCHITECTURE_IA64 = 6;
  PROCESSOR_ARCHITECTURE_AMD64 = 9;
begin
  GetNativeSystemInfo(ASystemInfo);
  Result := ASystemInfo.wProcessorArchitecture in [PROCESSOR_ARCHITECTURE_IA64,PROCESSOR_ARCHITECTURE_AMD64];
end;
Roy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 13.09.14 16:25 
Wie Frage ich denn nun diese Funktion ab?
Mit einer Procedur?

Bsp. Timer und Editfeld ??

Gruß Roy
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.09.14 21:46 
Du rufst die Funktion auf. Von wo aus hängt doch davon ab wo du diese Information brauchst und nicht von der Funktion. :gruebel:

Ein Timer macht keinen Sinn, da sich diese Information ja während der Laufzeit des Programms nicht ändert. Wenn du diese Information in einem Timerevent benötigst, kannst du sie ja beim Programmstart abfragen und speichern.
Roy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 13.09.14 23:04 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Ein Timer macht keinen Sinn, da sich diese Information ja während der Laufzeit des Programms nicht ändert. Wenn du diese Information in einem Timerevent benötigst, kannst du sie ja beim Programmstart abfragen und speichern.

Ja eben, es änderet sich ja nichts. Möchte nur in einem Edit oder Textfeld die aktuelle Version x86 oder x64 anzeigen lassen.
Speichern will ich garnichts!

Genau so wie abfrage: GetProzessorname
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.09.14 07:45 
Dann rufst du die Funktion am besten in FormCreate, also im OnCreate des Formulars, auf, aber wenn du GetProzessorname bereits benutzt, scheint das ja gar nicht das Problem zu sein. Aber wo ist denn dann dein Problem?
Funktioniert der Aufruf nicht? Stört dich, dass der Rückgabewert Boolean ist? ...

Wenn du nicht damit herausrückst wo eigentlich dein Problem ist, weiß ich auch nicht wie wir dir helfen können...
Delphi-Laie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1600
Erhaltene Danke: 232


Delphi 2 - RAD-Studio 10.1 Berlin
BeitragVerfasst: So 14.09.14 13:10 
Einfach die Größe eines Pointers ermitteln (SizeOf(Pointer)). Dieser ist unter 32 Bit 4, unter 64 Bit 8 Byte groß.
Stundenplan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 32

Win 7
Delphi 7 Pers., C# (VS 2010 Express)
BeitragVerfasst: So 14.09.14 13:56 
Das mit SizeOf(Pointer) funktioniert (zumindest bei meinem D7) nicht, da AFAIR die Pointergröße beim Kompilieren hardkodiert wird. (Ein auf einem 32bit-System kompiliertes Testprogrämmchen liefert auf einem 64bit-System immer noch 4. ;-))
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.09.14 14:11 
Richtig, die Größe des Pointers hat nichts mit dem System zu tun, sondern mit dem kompilierten Code des Programms. Der wiederum ändert sich logischerweise nicht je nachdem auf welchem System er läuft.
Delphi-Laie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1600
Erhaltene Danke: 232


Delphi 2 - RAD-Studio 10.1 Berlin
BeitragVerfasst: So 14.09.14 14:44 
Ja natürlich, ich bitte um Entschuldigung!

Allerdings frage ich mich, wie man überhaupt ermitteln kann, ob ein 64-Bit-Computer existiert, wenn nur ein 32-Bit-Betriebsprogramm darauf installiert ist. Es wurde in der Eingangsfrage ja das Wort "Rechner" benutzt, nicht etwa "Betriebssystem". Vermutlich können das Hardwarediagnoseprogramme.
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: So 14.09.14 18:02 
Der Typ der CPU ist zwar für das im Ausgangspost geschilderte Problem irrelevant, aber man könnte ihn z.B. mittels WMI ermitteln. Das folgende Programm wurde mit dem WMI Delphi Code Creator erstellt und nur leicht erweitert (Angabe des Prozessortyps):
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
//-----------------------------------------------------------------------------------------------------
//     This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.8.5.0
//     http://code.google.com/p/wmi-delphi-code-creator/
//     Blog http://theroadtodelphi.wordpress.com/wmi-delphi-code-creator/
//     Author Rodrigo Ruz V. (RRUZ) Copyright (C) 2011-2014 
//----------------------------------------------------------------------------------------------------- 
//
//     LIABILITY DISCLAIMER
//     THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
//     YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
//     DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
//
//----------------------------------------------------------------------------------------------------
program GetWMI_Info;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;
  
function ProcessorTypeAsString(ProcessorType: integer): string;
begin
  case ProcessorType of
    0:
      Result := 'x86';
    1:
      Result := 'MIPS';
    2:
      Result := 'Alpha';
    3:
      Result := 'PowerPC';
    5:
      Result := 'ARM';
    6:
      Result := 'Itanium-based systems';
    9:
      Result := 'x64';
    else
      Result := 'unknown';
  end;
end;
    
// Die Klasse "Win32_Processor" stellt eine Gerät zum Übersetzen von sequentiellen 
// Computeranweisungen in einem Win32-Computersystem dar. Für jeden Prozessor ist 
// eine Instanz dieser Klasse vorhanden.

procedure  GetWin32_ProcessorInfo;
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer        ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_Processor','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('AddressWidth    %d bit',[Integer(FWbemObject.AddressWidth)]));// Uint16
    Writeln(Format('Architecture    %s',[ProcessorTypeAsString(Integer(FWbemObject.Architecture))]));// Uint16
    Writeln('');
    FWbemObject:=Unassigned;
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_ProcessorInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode])); 
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;      
end.