Autor Beitrag
Gahero
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 193

Win Vista HP 64bit
Delphi 2007 Pro
BeitragVerfasst: Mo 20.08.07 17:39 
Hallo,

ich suche ein Tutorial für die API oder irgendwas, wo erklärt ist, wie man Systeminformationen auslesen kann (Hauptaugenmerk: vorhandene Hardware). Über die Registry hab ich das schon versucht, aber die Orte der einzelnen Schlüssel sind ja immer verschieden, das hilft mir also nicht weiter. Was mir so vorschwebt ist das mir das Programm CPU, Grafikkarte, Rammenge, OS, DirectX Version und sowas anzeigt. Kennt da jmd ein Tutorial zu, weil über Google hab ich wirklich nichts gefunden...

Moderiert von user profile iconAXMD: Titel geändert.
Gahero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 193

Win Vista HP 64bit
Delphi 2007 Pro
BeitragVerfasst: Di 21.08.07 16:30 
Ok, hat sich geklärt, hab was gefunden. Kann nun jeden Eintrag in den win32 Klassen auslesen.
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Di 21.08.07 17:53 
Wäre toll wenn du noch reinschreiben könntest WIE du es gelöst hast :) (z.b. mit Code)
magic87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 7, PHP
BeitragVerfasst: Mi 22.08.07 08:35 
ja..würde auch gerne die Quelle wissen, woher du es jetzt hast? Wäre nett wenn du den Link noch eben posten würdest.
LG
magic
Gahero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 193

Win Vista HP 64bit
Delphi 2007 Pro
BeitragVerfasst: Mi 22.08.07 14:14 
Zitat:
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:
function GetWMIstring (wmiHost, wmiClass, wmiProperty : string):string;
var  // These are all needed for the WMI querying process
  Locator:  ISWbemLocator;
  Services: ISWbemServices;
  SObject:  ISWbemObject;
  ObjSet:   ISWbemObjectSet;
  SProp:    ISWbemProperty;
  Enum:     IEnumVariant;
  Value:    Cardinal;
  TempObj:  OleVariant;
  SN: string;
begin
  try
  Locator := CoSWbemLocator.Create;
   Services :=  Locator.ConnectServer(wmiHost, 'root\cimv2''''''',''0nil);
  ObjSet := Services.ExecQuery('SELECT * FROM '+wmiClass, 'WQL',
    wbemFlagReturnImmediately and wbemFlagForwardOnly , nil);
  Enum :=  (ObjSet._NewEnum) as IEnumVariant;
  while (Enum.Next(1, TempObj, Value) = S_OK) do
  begin
    SObject := IUnknown(tempObj) as ISWBemObject;
    SProp := SObject.Properties_.Item(wmiProperty, 0);
    if VarIsNull(SProp.Get_Value) then
      result := ''
    else
    begin
      SN := SProp.Get_Value;
      result :=  SN;
    end;
  end;
  except // Trap any exceptions (Not having WMI installed will cause one!)
   on exception do
    result := '';
   end;
end;


procedure TForm1.FormActivate(Sender: TObject);
var tmpstr : string;
begin
tmpstr := getWMIstring('','Win32_VideoController ','AdapterRAM');
  if tmpstr <> '' then Label1.caption:= tmpstr +' Bytes VideoRAM';
end;




Mit den Übergabewerten kann man nun auf jeden möglichen Eintrag in sämtlichen Klassen zugreifen. Man muss diese nur ändern. Der Code ist von hathor. Übersicht der Klassen gibts hier: msdn2.microsoft.com/...ibrary/aa394373.aspx
sh030169
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 07.09.07 14:38 
Titel: WMI auslesen
Hallo!

danke für deine Source! Ich habe diese bei mir in eine Form implementiert und es funktioniert!
Soweit so gut!

Jetzt habe ich ein Consolen Programm (ohne GUI und FORM) und möchte den selben Wert auslesen. Dabei läuft mit das Programm in die Exception!
Warum?

Anbei meine Source, was mache ich falsch?

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:
uses
  Windows,
  Messages,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  Inifiles,
  StdCtrls,
  NTCommon,
  UserMan,
  registry,
  ExtCtrls,
  WbemScripting_TLB, ActiveX,
  SysUtils;


function GetWMIstring (wmiHost, wmiClass, wmiProperty : string):string;
var  // These are all needed for the WMI querying process
  Locator:  ISWbemLocator;
  Services: ISWbemServices;
  SObject:  ISWbemObject;
  ObjSet:   ISWbemObjectSet;
  SProp:    ISWbemProperty;
  Enum:     IEnumVariant;
  Value:    Cardinal;
  TempObj:  OleVariant;
  SN: string;
begin
  try
  Locator := CoSWbemLocator.Create;
   Services :=  Locator.ConnectServer(wmiHost, 'root\cimv2''''''',''0nil);
  ObjSet := Services.ExecQuery('SELECT * FROM '+wmiClass, 'WQL',
    wbemFlagReturnImmediately and wbemFlagForwardOnly , nil);
  Enum :=  (ObjSet._NewEnum) as IEnumVariant;
  while (Enum.Next(1, TempObj, Value) = S_OK) do
  begin
    SObject := IUnknown(tempObj) as ISWBemObject;
    SProp := SObject.Properties_.Item(wmiProperty, 0);
    if VarIsNull(SProp.Get_Value) then
      result := ''
    else
    begin
      SN := SProp.Get_Value;
      result :=  SN;
    end;
  end;
  except // Trap any exceptions (Not having WMI installed will cause one!)
   on exception do
    result := 'Error';
   end;
end;

begin

writeln('Language = '+getWMIstring('','Win32_operatingSystem','oslanguage'));

readln;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 07.09.07 15:23 
1. Wozu hast du unter uses die Unit Forms, die macht die Exe alleine 250 Kilobyte größer oder so.
2. Bei mir funktioniert der Code... :nixweiss:
Das einzige, was ich mangels der Units geändert habe, ist NTCommon und UserMan aus der uses zu schmeißen. Kann es daran liegen?
sh030169
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 07.09.07 15:36 
die NTcommon und UserMan habe ich entfernt --> geht nicht!
Ich frage mich ob da irgendwas fehlt! Muss ich eine vielleicht eine WMI lib implementieren? Was ist bei dir anders?
Was ist der unterschied zwischen FORM und CONSOLE?
sh030169
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 07.09.07 15:39 
es haut ihn bei

ausblenden Delphi-Quelltext
1:
Locator := CoSWbemLocator.Create;					


raus