-
Notifications
You must be signed in to change notification settings - Fork 2
/
Conversa.WMI.pas
107 lines (94 loc) · 3.02 KB
/
Conversa.WMI.pas
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
unit Conversa.WMI;
// https://theroadtodelphi.com/2010/12/01/accesing-the-wmi-from-pascal-code-delphi-oxygene-freepascal/
// https://theroadtodelphi.com/2011/08/02/reading-the-smbios-tables-using-delphi/
// https://theroadtodelphi.com/2010/11/28/be-careful-when-you-import-the-microsoft-wmiscripting-library/
// https://theroadtodelphi.com/2011/08/02/reading-the-smbios-tables-using-delphi/
interface
function GetWin32_BaseBoardInfo: String;
implementation
uses
System.SysUtils,
Winapi.ActiveX,
System.Win.ComObj,
System.Variants;//introduced in delphi 6, if you use a older version of delphi you just remove this
function VarArrayToStr(const vArray: variant): string;
function _VarToStr(const V: variant): string;
var
Vt: integer;
begin
Vt := VarType(V);
case Vt of
varSmallint,varInteger : Result := IntToStr(integer(V));
varSingle, varDouble, varCurrency : Result := FloatToStr(Double(V));
varDate : Result := VarToStr(V);
varOleStr : Result := WideString(V);
varBoolean : Result := VarToStr(V);
varVariant : Result := VarToStr(Variant(V));
varByte : Result := char(byte(V));
varString : Result := String(V);
varArray : Result := VarArrayToStr(Variant(V));
end;
end;
var
i : integer;
begin
Result := '[';
if (VarType(vArray) and VarArray) = 0 then
Result := _VarToStr(vArray)
else
for i := VarArrayLowBound(vArray, 1) to VarArrayHighBound(vArray, 1) do
if i=VarArrayLowBound(vArray, 1) then
Result := Result+_VarToStr(vArray[i])
else
Result := Result+'|'+_VarToStr(vArray[i]);
Result := Result + ']';
end;
function VarStrNull(const V:OleVariant):string; //avoid problems with null strings
begin
Result := '';
if VarIsNull(V) then
Exit;
if VarIsArray(V) then
Result:=VarArrayToStr(V)
else
Result:=VarToStr(V);
end;
function GetWMIObject(const objectName: String): IDispatch; //create the Wmi instance
var
chEaten: Integer;
BindCtx: IBindCtx;
Moniker: IMoniker;
begin
OleCheck(CreateBindCtx(0, bindCtx));
OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker));
OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result));
end;
//The Win32_BaseBoard class represents a base board (also known as a motherboard
//or system board).
function Internal_GetWin32_BaseBoardInfo: String;
var
objWMIService : OLEVariant;
colItems : OLEVariant;
colItem : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin
objWMIService := GetWMIObject('winmgmts:\\localhost\root\CIMV2');
colItems := objWMIService.ExecQuery('SELECT * FROM Win32_BaseBoard','WQL',0);
oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
while oEnum.Next(1, colItem, iValue) = 0 do
begin
Result := VarStrNull(colItem.SerialNumber);
colItem := Unassigned;
end;
end;
function GetWin32_BaseBoardInfo: String;
begin;
CoInitialize(nil);
try
Result := Internal_GetWin32_BaseBoardInfo;
finally
CoUninitialize;
end;
end;
end.