Редактиране

Споделяне чрез


Creating a Timer Event with Win32_LocalTime or Win32_UTCTime

You can use the standard model of intrinsic events and event filters in combination with the Win32_LocalTime or Win32_UTCTime classes to receive a timed notification. The intrinsic method is a recommended way of generating timed events, as it is consistent with the rest of the Microsoft event model and supports complex scheduling conditions.

The Win32_LocalTime and Win32_UTCTime classes are singleton classes in the root\cimv2 namespace that represent the system clock. When queried, Win32_LocalTime returns the current time at the moment of data retrieval in a 24-hour clock with local reference. The Win32_UTCTime class returns the current time with UTC reference.

To generate timed or repeating events with Win32_LocalTime or Win32_UTCTime

  • Set up an intrinsic notification event filter for Win32_LocalTime or Win32_UTCTime that requests notification for a specific date and time.

For example, if the local time under Daylight Savings Time is 4 P.M. and the location is GMT -8, then Win32_LocalTime.Hour returns 16 and Win32_UTCTime.Hour returns 23.

The following code example describes how to create an event filter that signals a repeating event every day at midnight.

// Win32_LocalTime and Win32_UTCTime reside in root\cimv2 namespace. 
// Defining the EventNamespace allows the filter
// to be compiled in any namespace.
instance of __EventFilter as $FILT1
{
 Name  = "wake-up call";
 Query = "SELECT * FROM __InstanceModificationEvent WHERE "    
 "TargetInstance ISA \"Win32_LocalTime\" AND "
 "TargetInstance.Hour = 0 AND TargetInstance.Minute = 0 AND "
 "TargetInstance.Second = 0";
 QueryLanguage = "WQL";
 EventNamespace = "root\\cimv2";
};