こんにちはマスター。
パクリなくりですが、こんなんどでしょうか?
Microsoft WMI Scripting V1.2 Library は不要です。
procedure XXXXX();
function GetWMIObject(const objectName: String): IDispatch;
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;
var
ObjWMIService : OLEVariant;
oleItemList : OLEVariant;
oleItems : OLEVariant;
oleItem : OLEVariant;
iEnumList : IEnumVariant;
iEnum : IEnumvariant;
nValue : LongWord;
begin
ObjWMIService := GetWMIObject('winmgmts:\\localhost\root\cimv2');
oleItemList := objWMIService.ExecQuery('SELECT * FROM Win32_OperatingSystem','WQL',0);
iEnumList := IUnknown(oleItemList._NewEnum) as IEnumVariant;
while iEnumList.Next(1, oleItems, nValue) = S_OK do
begin
iEnum := IUnknown(oleItems.Properties_._NewEnum) as IEnumVariant;
while (iEnum.Next(1, oleItem, nValue) = S_OK) do
begin
if VarIsNull(oleItem) then Continue;
{適当にデータ処理・・・}
end;
end;
end;
DelphiXE Windows7
|