unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,
activex, comobj, ExtCtrls,
ShellAPI, ExceptionLog;
type
TForm1 =
class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
WbemScripting_TLB;
var
aLoc : ISWbemLocator;
aSrv : ISWbemServices;
aObjSet : ISWbemObjectSet;
pEnum : IEnumVARIANT;
vOut : OleVariant;
dwRetrieved : LongWord;
hRes : HResult;
sNetConnectionID, sNetConnectionStatus :
String;
iNetConnectionStatus : Integer;
function GetLocator : ISWbemLocator;
begin
if not Assigned(aLoc)
then
aLoc := CoSWbemLocator.Create;
result := aLoc;
end;
function GetServices : ISWbemServices;
begin
if not Assigned(aSrv)
then
aSrv := aLoc.ConnectServer ('
','
root\cimv2', '
','
','
','
',0,
nil);
result := aSrv;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Listbox1.Items.Clear;
aLoc := GetLocator;
aSrv := GetServices;
aObjSet := aSrv.ExecQuery ('
SELECT NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter', '
WQL', 0,
nil);
pEnum := aObjSet.Get__NewEnum
as IEnumVARIANT;
while (true)
do
begin
hRes := pEnum.Next (1, vOut, dwRetrieved);
if not (hRes = S_OK)
then
Break;
if (VarIsNull(vOut.NetConnectionID))
then
Continue;
sNetConnectionID := vOut.NetConnectionID;
iNetConnectionStatus := vOut.NetConnectionStatus;
if iNetConnectionStatus = 2
then
sNetConnectionStatus := '
verbunden';
if iNetConnectionStatus = 7
then
sNetConnectionStatus := '
nicht verbunden';
ListBox1.Items.Add(sNetConnectionID + '
= ' + sNetConnectionStatus);
end;
// VarClear(vOut);
// hRes := 0;
// pEnum := nil;
// aLoc := nil;
// aSrv := nil;
// aObjSet := nil;
end;
end.