-
Notifications
You must be signed in to change notification settings - Fork 3
/
Unit1.pas
66 lines (57 loc) · 1.7 KB
/
Unit1.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
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.ActiveX, System.Win.ComObj,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
Function GetMainBoardSerial : string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
edt1.Text := GetMainBoardSerial;
end;
function TForm1.GetMainBoardSerial: string;
var
objWMIService : OLEVariant;
colItems : OLEVariant;
ColItem : OLEVariant;
oEnum : IEnumVariant;
IValue : LongWord;
Function GetWMINobject (const objectName : string) : IDispatch;
var
chEaten : Integer;
BindCtx : IBindCtx;
Moniker : Imoniker;
OleStr: PWideChar;
Begin
OleCheck(CreateBindCtx(0, BindCtx));
OleStr := StringtoOLEStr(objectName);
try
OleCheck(MkParseDisplayName (BindCtx, OleStr, chEaten, Moniker));
finally
SysFreeString(OleStr);
end;
OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result));
end;
begin
Result := '';
objWMIservice := GetWMINObject('winmgmts:\\localhost\root\cimv2');
colItems := objWMIService.EXecQuery('Select SerialNumber From Win32_BaseBoard', 'WQL', 0);
oEnum := IUnknown(colItems._NewENum) as IEnumVariant;
if oEnum.Next (1, ColItem, Ivalue) = 0 then
Result := VarTostr(ColItem.SerialNumber);
end;
end.