Delphi响应WMI事件(响应网线断开)


需要在程序中响应网线断开的信息,用Delphi实现了一下。
uses
WbemScripting_TLB, ActiveX, ComObj;

type
TForm1 = class(TForm)
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure OnDisconnect(ASender: TObject;
const objWbemObject: ISWbemObject;
const objWbemAsyncContext: ISWbemNamedValueSet);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnDisconnect(ASender: TObject;
const objWbemObject: ISWbemObject;
const objWbemAsyncContext: ISWbemNamedValueSet);
begin
ShowMessage(network broken);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Locator: TSWbemLocator;
Services: ISWbemServices;
SinkClassesC: TSWbemSink;
SinkClassesD: TSWbemSink;
begin
Locator := TSWbemLocator.Create(self);
Services := Locator.ConnectServer(, \root\wmi, , , , , 0, nil);
SinkClassesD := TSWbemSink.Create(self); SinkClassesD.OnObjectReady := OnDisconnect; // Event Notifier

// Connect Async Event
Services.ExecNotificationQueryAsync(
SinkClassesD.DefaultInterface,
Select * from MSNdis_StatusMediaDisconnect,
WQL,
0, nil, nil);
end;
联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678