Advertisement
Advertisement
| 09.03.2008 at 11:25AM PDT, ID: 23700281 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
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: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: |
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, WbemScripting_TLB, activex, IpHlpApi;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
aString = array of string;
a2String = array [0..1] of aString;
type
pDevices = ^tDevices;
tDevices = record
Next : pDevices;
Vals : a2String;
end;
procedure CreateList;
procedure AddToList(Tablica : a2String);
procedure DestroyList;
procedure PrintAll(Memo : TMemo);
function getPropValue(sprop:ISWbemProperty):string;
procedure getAdapters(owner:TComponent; wmiClass : string; Model : aString);
var
Form1 : TForm1;
Root, Last : pDevices;
LAN_root, LAN_last : pLAN_Devices;
implementation
{$R *.dfm}
uses
IpTypes;
procedure CreateList;
begin
Root := nil;
Last := nil;
end;
procedure AddToList(Tablica : a2String);
var
NewOne : pDevices;
tmp_tablica : a2String;
i, n : integer;
begin
New(NewOne);
NewOne^.Next := nil;
n := Length(Tablica[0]);
SetLength(tmp_tablica[0], n);
SetLength(tmp_tablica[1], n);
for i := 0 to n - 1 do begin
tmp_tablica[0][i] := Tablica[0][i];
tmp_tablica[1][i] := Tablica[1][i];
end;
NewOne^.Vals := tmp_tablica;
if Root = nil then begin
Root := NewOne;
Last := Root;
end else begin
Last^.Next := NewOne;
Last := NewOne;
end;
end;
procedure DestroyList;
var
ToDelete : pDevices;
begin
while Root <> nil do begin
ToDelete := Root;
Root := Root^.Next;
Dispose(ToDelete);
end;
end;
procedure PrintAll(Memo : TMemo);
var
Lista : pDevices;
Lista_ : a2String;
i, n : integer;
begin
Lista := Root;
while Lista <> nil do begin
Lista_ := Lista^.Vals;
n := Length(Lista_[0]);
for i := 0 to n - 1 do Memo.Lines.Add(' ------ ' + Lista_[0][i] + ': ' + Lista_[1][i]);
Lista := Lista^.Next;
Memo.Lines.Add('');
end;
DestroyList;
end;
function getPropValue(sprop:ISWbemProperty):string;
var
sValue : string;
count : integer;
begin
sValue := '';
if VarIsNull(SProp.Get_Value) then sValue := 'null'
else
case SProp.CIMType of
wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeSint16, wbemCimtypeUint16,
wbemCimtypeSint32, wbemCimtypeUint32, wbemCimtypeSint64:
sValue := IntToStr(SProp.Get_Value);
wbemCimtypeString, wbemCimtypeUint64:
if VarIsArray(SProp.Get_Value) then begin
if VarArrayHighBound(SProp.Get_Value, 1) > 0 then
for Count := 1 to VarArrayHighBound(SProp.Get_Value, 1) do
sValue := sValue + ' ' + SProp.Get_Value[Count];
end else sValue := SProp.Get_Value;
wbemCimtypeDatetime:
sValue:=SProp.Get_Value;
else
Exception.Create('Unknown type');
end; {case}
result:=sValue;
end;
procedure getAdapters(owner:TComponent; wmiClass : string; Model : aString);
var
Locator : TSWbemLocator;
SinkClasses : TSWbemSink;
Services : ISWbemServices;
ObjectSet : ISWbemObjectSet;
SObject : ISWbemObject;
propSet : ISWbemPropertySet;
SProp : ISWbemProperty;
Enum : IEnumVariant;
tempObj : OleVariant;
Value : Cardinal;
sValue : String;
i, j, w1 : integer;
data : a2String;
test : boolean;
begin
w1 := Length(Model);
SetLength(data[0], w1);
SetLength(data[1], w1);
Locator := TSWbemLocator.Create(owner);
SinkClasses := TSWbemSink.Create(owner);
try
SinkClasses.Cancel;
Services := Locator.ConnectServer('.', 'root\CIMV2', '', '', '', '', 0, nil);
ObjectSet := Services.InstancesOf(wmiClass, wbemFlagReturnImmediately or wbemQueryFlagShallow, nil);
Enum := (ObjectSet._NewEnum) as IEnumVariant;
SetLength(Model, w1);
CreateList;
while (Enum.Next(1, tempObj, Value) = S_OK) do begin
SObject := IUnknown(tempObj) as SWBemObject;
propSet := SObject.Properties_;
test := false;
for j := 0 to w1 - 1 do begin
data[0][j] := Model[j];
data[1][j] := '';
SProp := propSet.Item(Model[j], 0);// caption or systemname
sValue := getPropValue(SProp);
if sValue<>'null' then begin
data[1][j] := sValue;
test := true;
end;
end;
if test then AddToList(data);
end; {while Enum}
finally
end; {try}
Locator.Free;
SinkClasses.Free;
Services:=nil;
ObjectSet:=nil;
SObject:=nil;
enum:=nil;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Model : aString;
begin
Memo1.Clear;
Memo1.Lines.Add(''); Memo1.Lines.Add('Procesor');
SetLength(Model, 4);
Model[0] := 'Name'; Model[1] := 'Description'; Model[2] := 'CurrentClockSpeed'; Model[3] := 'ProcessorId';
getAdapters(self, 'Win32_Processor', Model);
PrintAll(Memo1);
SetLength(Model, 1);
Model[0] := 'NumberOfProcessors';
getAdapters(self, 'Win32_ComputerSystem', Model);
PrintAll(Memo1);
Memo1.SetFocus;
end;
end.
|