我正在使用Delphi 7而我试图列出所有ENABLED网络适配器不仅连接 我有这个代码,但它只显示连接的适配器
procedure GetAdapters;
var
oBindObj : IDispatch;
oNetAdapters,oNetAdapter,
odnsAddr,oWMIService : OleVariant;
i ,iValue : longword;
oEnum : IEnumvariant;
oCtx : IBindCtx;
oMk : IMoniker;
sFileObj : widestring;
begin
Form1.sComboBox1.Items.Clear;
sFileObj := 'winmgmts:\\.\root\cimv2';
OleCheck(CreateBindCtx(0,oCtx));
OleCheck(MkParseDisplayNameEx(oCtx,PWideChar(sFileObj),i,oMk));
OleCheck(oMk.BindToObject(oCtx,nil,IUnknown,oBindObj));
oWMIService := oBindObj;
oNetAdapters := oWMIService.ExecQuery('Select * from ' +
'Win32_NetworkAdapterConfiguration ' + 'where IPEnabled=TRUE');
oEnum := IUnknown(oNetAdapters._NewEnum) as IEnumVariant;
while oEnum.Next(1,oNetAdapter,iValue) = 0 do begin
try
Form1.sCombobox1.Items.Add(oNetAdapter.Caption);
except
end;
oNetAdapter := Unassigned;
end;
odnsAddr := Unassigned;
oNetAdapters := Unassigned;
oWMIService := Unassigned;
end;
当我从代码中删除此+ 'where IPEnabled=TRUE'
时,它向我展示了大约17个适配器,但我只需要显示在网络适配器下的Windows设备管理器中列出的适配器