unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj, ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ActiveDs_TLB;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
wmi : variant;
wmiService : variant;
nicstatus : variant;
card : Olevariant;
cnt : integer;
Enum: IEnumVariant;
P : IUnknown;
F : Cardinal;
connected : integer;
status : string;
begin
WMI:=CreateOleObject('WbemScripting.SWbemLocator');
wmiService := wmi.ConnectServer('.', 'root\wmi');
nicstatus := wmiService.InstancesOf('MSNdis_MediaConnectStatus');
p := nicstatus._NewEnum;
p.QueryInterface(IEnumVariant, Enum);
for cnt := 0 to nicstatus.Count - 1 do
begin
Enum.Next(1, card, F);
connected := card.NdisMediaConnectStatus;
if (connected = 0) then
Status := 'connected'
else
Status := 'network cable unplugged';
ShowMessage(card.InstanceName + ' : ' + Status);
end;
end;
function IsNetworkAlive(flags : LPDWORD) : boolean; stdcall; external 'sensapi.dll';
procedure ShowNetworkStatus;
var
Flags : DWORD;
Res : boolean;
begin
Res := IsNetworkAlive(@Flags);
if Res then
ShowMessage('Network connection is active')
else
ShowMessage('network cable unplugged');
end;
end.
Comments
Post a Comment