Menu
Home
Products
  WmiSet Components
    Release History
    TWmiQuery
    TWmiProcessControl
    TWmiOs
    TWmiRegistry
    TWmiConnection
    TWmiStorageInfo
    TWmiDiskQuotaControl
    TWmiMethod
    TWmiPerformanceMonitor
  NTSet components
  "How to" zone
  Shareware
  Full version
  Archive
  NTSet
  WmiSet
Contact us
Advanced search
Site map

Quick search

Advanced search

New version notify
e-mail address: Subscribe Unsubscribe
Privacy statement
TWmiSystemEvents component
TWmiSystemEvents is a part of WmiSet Component Collection for Delphi, C++Builder. It allows to receive notifications when expected event happens on a local or remote computer. The component declares the following events:
  • OnCDROMInserted: Occurs when a disk is inserted into a CDROM drive;
  • OnCDROMEjected: Occurs when a disk is ejected from a CDROM drive;
  • OnDocking: Occurs when the laptop is docked or undocked to/from the docking station. (Windows XP or higher)
  • OnEventLogAny: Occurs when the new event record is written into any event log.
  • OnEventLogApplication: Occurs when the new event record is written into Application event log.
  • OnEventLogSecurity: Occurs when the new event record is written into Security event log.
  • OnEventLogSystem: Occurs when the new event record is written into System event log.
  • OnGroupAccount: Occurs when a user groups is created, deleted or modified.
  • OnGroupMembership: Occurs when the list of user group members changes.
  • OnNetworkConnect: Occurs when the network connection is detected.
  • OnNetworkDisconnect: Occurs when the system detects the network disconnect.
  • OnPrinter: Occurs when the changes in the printers configuration are detected.
  • OnPrintJob: Occurs when the print job starts, finishes or changes status.
  • OnService: Occurs when the change in list of service is detected.
  • OnUserAccount: Occurs when the change in the list of user accounts is detected.
  • OnUserLogoff: Occurs when a user logs off the system. (Windows XP or higher)
  • OnUserLogon: Occurs when a user logs on the system. (Windows XP or higher)
  • Suggest new event
Code Example: registering new events.
TWmiSystemEvents component allows to register for new event types. This feature requires advanced knowledge of WQL. The code below registers the event that will be fired when a new file is created in the directory c:\temp. This example assumes that WmiSystemEvents1 component was dropped on the form at design time.
procedure Form1.Button1Click(Sender: TObject);
var
  vWQL: widestring;
begin
  WmiSystemEvents1.Active := true;
  // test an event that will be fired when 
  // a new file is created in the c:\temp directory.
  vWQL := 'SELECT * FROM __InstanceCreationEvent '+
          'WITHIN 5 '+
          'WHERE '+
          '  Targetinstance ISA '+
          '    "CIM_DirectoryContainsFile" '+
          '  and TargetInstance.GroupComponent = '+
          '    "Win32_Directory.Name=''c:\\temp''"';
  WmiSystemEvents1.RegisterWmiEvent('root\cimv2', 
                                    vWQL, '', 
                                    OnFileCreated, []);
end;

procedure TTestWmiEvents.OnFileCreated(
    Sender: TObject;
    EventInfo: TEventInfoHolder; 
    Event: OleVariant);
begin
  ShowMessage('The new file created: '+
              Event.TargetInstance.PartComponent);
end;

              
Demo project.
WmiSet component collection comes with a complete example that shows how to use all of the events declared by TWmiSystemEvents component. Click on the image to download the compiled binary. Download WmiSet to be able to recompile the example.