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
| procedure TForm1.Button1Click(Sender: TObject);
var
i, j, c: Integer;
wmiLocator: TSWbemLocator;
wmiServices: ISWbemServices;
AMachine, ARoot, AUser, APwd: string;
wmiObjectSet: ISWbemObjectSet;
wmiObject: ISWbemObject;
wmiProp: ISWbemProperty;
propSet: ISWbemPropertySet;
propEnum, Enum: IEnumVariant;
v: OleVariant;
n: LongWord;
xIDSession: string;
begin
AMachine := '192.168.1.55';
ARoot := 'root\cimv2';
AUser := 'ADMINISTRATEUR';
APwd := 'AZERTY';
xIDSession := '';
try
wmiLocator := TSWbemLocator.Create(nil);
wmiServices := wmiLocator.ConnectServer(AMachine, ARoot, AUser, APwd, '', '', 0, nil);
wmiObjectSet := wmiServices.ExecQuery('SELECT SessionID FROM Win32_Process WHERE Name = "explorer.exe"', 'WQL', wbemFlagReturnImmediately, nil);
Enum := (wmiObjectSet._NewEnum) as IEnumVariant;
c := wmiObjectSet.Count;
if c > 0 then
sg.ColCount := c + 1;
sg.Cells[0, 0] := 'Fetching...';
sg.Update;
Enum := (wmiObjectSet._NewEnum) as IEnumVariant;
i := 1;
while (Enum.Next(1, v, n) = S_OK) do begin
wmiObject := IUnknown(v) as SWBemObject;
if sg.RowCount <> wmiObject.Properties_.Count + 1 then
sg.RowCount := wmiObject.Properties_.Count + 1;
propSet := wmiObject.Properties_;
sg.Cells[i, 0] := IntToStr(i);
propEnum := (propSet._NewEnum) as IEnumVariant;
j := 1;
while (propEnum.Next(1, v, n) = S_OK) do begin
wmiProp := IUnknown(v) as SWBemProperty;
sg.Cells[0, j] := wmiProp.Name;
sg.Cells[i, j] := WmiGetPropStr(wmiProp);
Inc(j);
end;
Inc(i);
end;
xIDSession := sg.Cells[1, 2];
Label1.Caption := xIDSession;
Except
on e: Exception do
begin
showmessage(e.Message);
end;
end;
end; |
Partager