Delphi WMI[2] 响应网线断开

Delphi WMI[2] 响应网线断开

uses
  WbemScripting_TLB,ActiveX,ComObj;

procedure OnDisconnect(Sender: TObject;
                           var objWbemObject: OleVariant;
                           var objWbemAsyncContext: OleVariant);


procedure TForm1.OnDisconnect(Sender: TObject;       
  var objWbemObject: OleVariant;
  var objWbemAsyncContext: OleVariant);
begin
  ShowMessage(' 网络中断啦! TaoRoy');
end;

procedure TForm1.BitBtn11Click(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;

  

 

创建时间:2021.07.28  更新时间:

 

posted on 2021-07-28 16:21  滔Roy  阅读(228)  评论(0编辑  收藏  举报

导航