转换了一个Delphi版本的:<br>uses WbemScripting_TLB; ////其中,WbemScripting_TLB.pas可从<br> ///http://www.truth4all.org/WbemScripting_TLB.pas下载<br>function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;<br>var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecall; external 'activeds.dll';<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> Locator: ISWbemLocator;<br> oService: ISWbemServices;<br> oObjs: ISWbemObjectSet;<br> Enum: IEnumVARIANT;<br> varArr: OleVariant;<br> lNumElements: ULong;<br> AName: array[0..255] of Char;<br> ASize: DWORD;<br> Server: string;<br>begin<br> Server := '';<br> ASize := SizeOf(AName) - 1;<br> if GetComputerName(@AName, ASize) then Server := AName;<br><br> Locator := CoSWbemLocator.Create; // 'root/cimv2'<br> oService := Locator.ConnectServer(Server, 'root/microsoft/homenet', '',<br> '', '', '', 0, nil);<br> oObjs := oService.ExecQuery('Select * from HNet_Connection', 'WQL',<br> wbemFlagBidirectional, nil);<br> Enum := oObjs._NewEnum as IEnumVariant;<br> while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements))) and<br> (lNumElements > 0) do<br> begin<br> ShowMessage((IUnknown(varArr) as SWBemObject).GetObjectText_(0));<br> end;<br>end;<br>大家共同学习:)