其实不需要任何第三方的东西 ,d5 就 OK。下面是我写的源代码,完整奉献。记得要谢谢我
<br>------------------------------------------------------------------------------<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> WbemScripting_TLB, OleServer, StdCtrls,ActiveX;<br><br>type<br> TForm1 = class(TForm)<br> WbemLocator: TSWbemLocator;<br> Memo1: TMemo;<br> GroupBox1: TGroupBox;<br> Button3: TButton;<br> Button4: TButton;<br> Sink: TSWbemSink;<br> GroupBox2: TGroupBox;<br> Button2: TButton;<br> Button6: TButton;<br> Label1: TLabel;<br> GroupBox3: TGroupBox;<br> Button5: TButton;<br> Button7: TButton;<br> Button8: TButton;<br> Button9: TButton;<br> Button10: TButton;<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> procedure Button4Click(Sender: TObject);<br> procedure Button5Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure SinkObjectReady(Sender: TObject; var objWbemObject,<br> objWbemAsyncContext: OleVariant);<br> procedure Button6Click(Sender: TObject);<br> procedure Button7Click(Sender: TObject);<br> procedure Button8Click(Sender: TObject);<br> procedure Button9Click(Sender: TObject);<br> procedure Button10Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br><br> ObjSet:ISWBEMobjectSet;<br> Obj:ISWBEMobject;<br><br> Prop:ISWbemProperty;<br><br> Enum:IEnumVARIANT;<br> Sql:string;<br> i:integer;<br> c:Cardinal;<br> OV:OleVariant;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/default','','','','',0,nil);<br> Sql:='Select * from TestClass';<br> ObjSet:= Srv.ExecQuery(Sql,'WQL',0,nil);<br> Enum:=IEnumVARIANT(ObjSet._NewEnum);<br><br> Enum.Reset;<br> For i:=0 to ObjSet.Count-1 do begin<br> Enum.Next(1,OV,C);<br> Obj:= IUnknown(OV) as ISWBEMObject;<br> Prop:=Obj.Properties_.Item('name',0);<br> Memo1.Lines.add(Prop.Get_Value);<br> Prop:=Obj.Properties_.Item('age',0);<br> Memo1.Lines.add(Prop.Get_Value);<br> Prop:=Obj.Properties_.Item('address',0);<br> Memo1.Lines.add(Prop.Get_Value);<br> Memo1.Lines.add('');<br> end;<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> Obj:ISWBEMObject;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/cimv2','','','','',0,nil);<br> ObjSet:=Srv.InstancesOf('__namespace',0,nil);<br> obj:=objset.Item('__NAMESPACE.Name="ggc2"',0);<br> obj.Delete_(0,nil);<br>end;<br><br>procedure TForm1.Button4Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> Obj:ISWBEMObject;<br> OV:OleVariant;<br> Prop:ISWBEMProperty;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/cimv2','','','','',0,nil);<br> ObjSet:=Srv.InstancesOf('__namespace',0,nil);<br> obj:=objset.Item('__NAMESPACE.Name="ggc1"',0).SpawnInstance_(0);<br><br> OV:='kkee';<br> Prop:=Obj.Properties_.Item('name',0);<br> Prop.Set_Value(OV);<br><br><br>// 或<br>// prop:=obj.Properties_.Add('name',0,false,0);<br>// Prop.Set_Value(OV);<br><br> Obj.Put_(0,Obj.Properties_);<br>end;<br><br>procedure TForm1.Button5Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> Obj,OBj2:ISWBEMObject;<br> OV:OleVariant;<br> PropSet:ISWBEMPropertySet;<br> Prop:ISWBEMProperty;<br><br> Enum:IEnumVARIANT;<br> i:integer;<br> c:Cardinal;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/default','','','','',0,nil);<br> Obj:=Srv.Get('',0,nil);<br><br> propSet:=Obj.Properties_;<br>{ Enum:=IEnumVARIANT(Propset.Get__NewEnum);<br> for i:=0 to Propset.Count-1 do begin<br> Enum.Next(1,OV,c);<br> Prop:= IUnknown(OV) as ISWBEMProperty;<br> Memo1.Lines.Add(prop.name);<br> end;<br> Exit; }<br><br><br> Obj.Path_.Class_:='TestClass';<br><br> Prop:=PropSet.Add('name',WBEMCIMTYPESTRING,False,0);<br> OV:=True;<br> Prop.Qualifiers_.Add('key',OV,True,True,True,0);<br><br> PropSet.Add('age',WBEMCIMTYPESTRING,False,0);<br> PropSet.Add('Address',WBEMCIMTYPESTRING,False,0);<br><br> Obj.Put_(0,PropSet);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> Obj:ISWBEMObject;<br> OV:OleVariant;<br> Prop:ISWBEMProperty;<br> Query:String;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','','','','','',0,nil);<br> Query := 'SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA ''Win32_Process''';<br> Srv.ExecNotificationQueryAsync(Sink.DefaultInterface,Query,'WQL',0,nil,nil);<br>end;<br><br>procedure TForm1.SinkObjectReady(Sender: TObject; var objWbemObject,<br> objWbemAsyncContext: OleVariant);<br>var O:SWBEMObject;<br> P,Prop:SWBEMProperty;<br> Enum:IEnumVARIANT;<br> OV:OleVariant;<br> PropSet:SWBEMPropertySet;i:integer;c:cardinal;<br>begin<br> O:=IUnknown(objWbemObject) as SWBEMObject;<br><br> P:=O.Properties_.Item('TargetInstance',0);<br> O:=IUnknown(P.Get_Value) as SWBEMObject;<br><br> P:=O.Properties_.Item('Name',0);<br> Memo1.lines.add(P.Get_Value);<br><br>{ PropSet:=O.Properties_;<br> Enum:=IEnumVARIANT(Propset.Get__NewEnum);<br> for i:=0 to Propset.Count-1 do begin<br> Enum.Next(1,OV,c);<br> Prop:= IUnknown(OV) as ISWBEMProperty;<br> Memo1.Lines.Add(prop.name);<br> end;}<br>end;<br><br>procedure TForm1.Button6Click(Sender: TObject);<br>begin<br> Sink.Cancel;<br>end;<br><br>procedure TForm1.Button7Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> ClassObj,OBj:ISWBEMObject;<br> OV:OleVariant;<br> PropSet:ISWBEMPropertySet;<br> Prop:ISWBEMProperty;<br><br> Enum:IEnumVARIANT;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/default','','','','',0,nil);<br><br> ClassObj:=Srv.Get('TestClass',0,nil);<br> Obj:=ClassObj.SpawnInstance_(0);<br><br> propSet:=Obj.Properties_;<br><br> Prop:=Obj.Properties_.Item('name',0);<br> OV:='龚谷初';<br> Prop.Set_Value(OV);<br><br> Prop:=Obj.Properties_.Item('age',0);<br> OV:='30';<br> Prop.Set_Value(OV);<br><br> Prop:=Obj.Properties_.Item('address',0);<br> OV:='常德市青年南路';<br> Prop.Set_Value(OV);<br><br> Obj.Put_(0,PropSet);<br>// another instance<br> Obj:=ClassObj.SpawnInstance_(0);<br><br> propSet:=Obj.Properties_;<br><br> Prop:=Obj.Properties_.Item('name',0);<br> OV:='林新良';<br> Prop.Set_Value(OV);<br><br> Prop:=Obj.Properties_.Item('age',0);<br> OV:='29';<br> Prop.Set_Value(OV);<br><br> Prop:=Obj.Properties_.Item('address',0);<br> OV:='澧县电力局';<br> Prop.Set_Value(OV);<br><br> Obj.Put_(0,PropSet);<br>end;<br><br><br>procedure TForm1.Button8Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> ClassObj,OBj:ISWBEMObject;<br> OV:OleVariant;<br> PropSet:ISWBEMPropertySet;<br> Prop:ISWBEMProperty;<br><br> Enum:IEnumVARIANT;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/default','','','','',0,nil);<br><br> ObjSet:=Srv.InstancesOf('TestClass',0,nil);<br> <br> Obj:=ObjSet.Item('TestClass.name="lxl"',0);<br> Obj.Delete_(0,nil);<br><br> Obj:=ObjSet.Item('TestClass.name="lxggc"',0);<br> Obj.Delete_(0,nil);<br> <br>end;<br><br>procedure TForm1.Button9Click(Sender: TObject);<br>var Srv:ISWBEMServices;<br> ObjSet:ISWBEMobjectSet;<br> Obj:ISWBEMObject;<br>begin<br> Srv:=WbemLocator.ConnectServer('.','root/default','','','','',0,nil);<br> Obj:=Srv.Get('TestClass',0,nil);<br> Obj.Delete_(0,nil);<br>end;<br><br>procedure TForm1.Button10Click(Sender: TObject);<br>begin<br> memo1.lines.clear;<br>end;<br><br>end.