ManagementEventWatcher Oluşturucular
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
ManagementEventWatcher sınıfının yeni bir örneğini başlatır.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| ManagementEventWatcher() |
ManagementEventWatcher sınıfının yeni bir örneğini başlatır. Daha fazla başlatma için nesnedeki özellikleri ayarlayın. Bu, parametresiz oluşturucudur. |
| ManagementEventWatcher(EventQuery) |
WMI ManagementEventWatcher verildiğinde sınıfın yeni bir örneğini başlatır. |
| ManagementEventWatcher(String) |
Dize biçiminde bir WMI ManagementEventWatcher verildiğinde sınıfının yeni bir örneğini başlatır. |
| ManagementEventWatcher(ManagementScope, EventQuery) |
Sınıfın verilen WMI ManagementEventWatcher uygun olayları dinleyen yeni bir örneğini başlatır. |
| ManagementEventWatcher(String, String) |
Sınıfın verilen WMI ManagementEventWatcher uygun olayları dinleyen yeni bir örneğini başlatır. Bu değişken için sorgu ve kapsam dize olarak belirtilir. |
| ManagementEventWatcher(ManagementScope, EventQuery, EventWatcherOptions) |
Belirtilen seçeneklere ManagementEventWatcher göre verilen WMI olay sorgusuna uygun olayları dinleyen sınıfın yeni bir örneğini başlatır. Bu değişken için sorgu ve kapsam belirtilen nesnelerdir. options nesnesi zaman aşımı ve bağlam bilgileri gibi seçenekleri belirtebilir. |
| ManagementEventWatcher(String, String, EventWatcherOptions) |
Belirtilen seçeneklere ManagementEventWatcher göre verilen WMI olay sorgusuna uygun olayları dinleyen sınıfın yeni bir örneğini başlatır. Bu değişken için sorgu ve kapsam dize olarak belirtilir. options nesnesi zaman aşımı ve bağlam bilgileri gibi seçenekleri belirtebilir. |
ManagementEventWatcher()
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
ManagementEventWatcher sınıfının yeni bir örneğini başlatır. Daha fazla başlatma için nesnedeki özellikleri ayarlayın. Bu, parametresiz oluşturucudur.
public:
ManagementEventWatcher();
public ManagementEventWatcher();
Public Sub New ()
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
WqlEventQuery query =
new WqlEventQuery("__InstanceCreationEvent",
new TimeSpan(0,0,1),
"TargetInstance isa \"Win32_Process\"");
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher();
watcher.Query = query;
// times out watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = new TimeSpan(0,0,5);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As New WqlEventQuery( _
"__InstanceCreationEvent", _
New TimeSpan(0, 0, 1), _
"TargetInstance isa ""Win32_Process""")
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher
watcher.Query = query
' times watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = New TimeSpan(0, 0, 5)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
ManagementEventWatcher(EventQuery)
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
WMI ManagementEventWatcher verildiğinde sınıfın yeni bir örneğini başlatır.
public:
ManagementEventWatcher(System::Management::EventQuery ^ query);
public ManagementEventWatcher(System.Management.EventQuery query);
new System.Management.ManagementEventWatcher : System.Management.EventQuery -> System.Management.ManagementEventWatcher
Public Sub New (query As EventQuery)
Parametreler
- query
- EventQuery
EventQuery İzleyicinin dinleyeceği olayları belirleyen WMI olay sorgusunu temsil eden bir sorgu.
Örnekler
Bu kod örneğinde istemci, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda bildirim alır. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher(new EventQuery(query));
// times out watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = new TimeSpan(0,0,5);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM __InstanceCreationEvent " _
& "WITHIN 1 WHERE " & _
"TargetInstance isa ""Win32_Process"""
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher(New EventQuery( _
query))
' times watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = New TimeSpan(0, 0, 5)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
İzleyicinin olayları dinleyeceği ad alanı, şu anda ayarlanmış olan varsayılan ad alanıdır.
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
ManagementEventWatcher(String)
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
Dize biçiminde bir WMI ManagementEventWatcher verildiğinde sınıfının yeni bir örneğini başlatır.
public:
ManagementEventWatcher(System::String ^ query);
public ManagementEventWatcher(string query);
new System.Management.ManagementEventWatcher : string -> System.Management.ManagementEventWatcher
Public Sub New (query As String)
Parametreler
- query
- String
İzleyicinin dinleyeceği olayları tanımlayan bir WMI olay sorgusu.
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher(query);
// times out watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = new TimeSpan(0,0,5);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM __InstanceCreationEvent " _
& "WITHIN 1 WHERE " & _
"TargetInstance isa ""Win32_Process"""
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher(query)
' times watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = New TimeSpan(0, 0, 5)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
İzleyicinin olayları dinleyeceği ad alanı, şu anda ayarlanmış olan varsayılan ad alanıdır.
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
ManagementEventWatcher(ManagementScope, EventQuery)
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
Sınıfın verilen WMI ManagementEventWatcher uygun olayları dinleyen yeni bir örneğini başlatır.
public:
ManagementEventWatcher(System::Management::ManagementScope ^ scope, System::Management::EventQuery ^ query);
public ManagementEventWatcher(System.Management.ManagementScope scope, System.Management.EventQuery query);
new System.Management.ManagementEventWatcher : System.Management.ManagementScope * System.Management.EventQuery -> System.Management.ManagementEventWatcher
Public Sub New (scope As ManagementScope, query As EventQuery)
Parametreler
- scope
- ManagementScope
ManagementScope İzleyicinin olayları dinleyeceği kapsamı (ad alanı) temsil eden.
- query
- EventQuery
EventQuery İzleyicinin dinleyeceği olayları belirleyen WMI olay sorgusunu temsil eden bir sorgu.
Örnekler
Bu kod örneğinde istemci, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda bildirim alır. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher(
new ManagementScope("root\\CIMV2"),
new EventQuery(query));
// times out watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = new TimeSpan(0,0,5);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM __InstanceCreationEvent " _
& "WITHIN 1 WHERE " & _
"TargetInstance isa ""Win32_Process"""
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher( _
New ManagementScope("root\CIMV2"), _
New EventQuery(query))
' times watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = New TimeSpan(0, 0, 5)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
ManagementEventWatcher(String, String)
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
Sınıfın verilen WMI ManagementEventWatcher uygun olayları dinleyen yeni bir örneğini başlatır. Bu değişken için sorgu ve kapsam dize olarak belirtilir.
public:
ManagementEventWatcher(System::String ^ scope, System::String ^ query);
public ManagementEventWatcher(string scope, string query);
new System.Management.ManagementEventWatcher : string * string -> System.Management.ManagementEventWatcher
Public Sub New (scope As String, query As String)
Parametreler
- scope
- String
İzleyicinin olayları dinleyeceği yönetim kapsamı (ad alanı).
- query
- String
İzleyicinin dinleyeceği olayları tanımlayan sorgu.
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher("root\\CIMV2",
query);
// times out watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = new TimeSpan(0,0,5);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM __InstanceCreationEvent " _
& "WITHIN 1 WHERE " & _
"TargetInstance isa ""Win32_Process"""
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher( _
"root\CIMV2", query)
' times watcher.WaitForNextEvent in 5 seconds
watcher.Options.Timeout = New TimeSpan(0, 0, 5)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
ManagementEventWatcher(ManagementScope, EventQuery, EventWatcherOptions)
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
Belirtilen seçeneklere ManagementEventWatcher göre verilen WMI olay sorgusuna uygun olayları dinleyen sınıfın yeni bir örneğini başlatır. Bu değişken için sorgu ve kapsam belirtilen nesnelerdir. options nesnesi zaman aşımı ve bağlam bilgileri gibi seçenekleri belirtebilir.
public:
ManagementEventWatcher(System::Management::ManagementScope ^ scope, System::Management::EventQuery ^ query, System::Management::EventWatcherOptions ^ options);
public ManagementEventWatcher(System.Management.ManagementScope scope, System.Management.EventQuery query, System.Management.EventWatcherOptions options);
new System.Management.ManagementEventWatcher : System.Management.ManagementScope * System.Management.EventQuery * System.Management.EventWatcherOptions -> System.Management.ManagementEventWatcher
Public Sub New (scope As ManagementScope, query As EventQuery, options As EventWatcherOptions)
Parametreler
- scope
- ManagementScope
ManagementScope İzleyicinin olayları dinleyeceği kapsamı (ad alanı) temsil eden.
- query
- EventQuery
EventQuery İzleyicinin dinleyeceği olayları belirleyen WMI olay sorgusunu temsil eden bir sorgu.
- options
- EventWatcherOptions
EventWatcherOptions Olayları izlemek için kullanılan ek seçenekleri temsil eden.
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Event options
// blockSize = 1, so wait for 1 event to return
EventWatcherOptions options = new EventWatcherOptions(
null, TimeSpan.MaxValue, 1);
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher(
new ManagementScope("root\\CIMV2"),
new EventQuery(query), options);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM __InstanceCreationEvent " _
& "WITHIN 1 WHERE " & _
"TargetInstance isa ""Win32_Process"""
' Event options
' blockSize = 1, so wait for 1 event to return
Dim options As New EventWatcherOptions( _
Nothing, TimeSpan.MaxValue, 1)
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher( _
New ManagementScope("root\CIMV2"), _
New EventQuery(query), _
options)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
ManagementEventWatcher(String, String, EventWatcherOptions)
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
- Kaynak:
- ManagementEventWatcher.cs
Belirtilen seçeneklere ManagementEventWatcher göre verilen WMI olay sorgusuna uygun olayları dinleyen sınıfın yeni bir örneğini başlatır. Bu değişken için sorgu ve kapsam dize olarak belirtilir. options nesnesi zaman aşımı ve bağlam bilgileri gibi seçenekleri belirtebilir.
public:
ManagementEventWatcher(System::String ^ scope, System::String ^ query, System::Management::EventWatcherOptions ^ options);
public ManagementEventWatcher(string scope, string query, System.Management.EventWatcherOptions options);
new System.Management.ManagementEventWatcher : string * string * System.Management.EventWatcherOptions -> System.Management.ManagementEventWatcher
Public Sub New (scope As String, query As String, options As EventWatcherOptions)
Parametreler
- scope
- String
İzleyicinin olayları dinleyeceği yönetim kapsamı (ad alanı).
- query
- String
İzleyicinin dinleyeceği olayları tanımlayan sorgu.
- options
- EventWatcherOptions
EventWatcherOptions Olayları izlemek için kullanılan ek seçenekleri temsil eden.
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Event options
// blockSize = 1, so wait for 1 event to return
EventWatcherOptions options = new EventWatcherOptions(
null, TimeSpan.MaxValue, 1);
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher(
new ManagementScope("root\\CIMV2"),
new EventQuery(query), options);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM __InstanceCreationEvent " _
& "WITHIN 1 WHERE " & _
"TargetInstance isa ""Win32_Process"""
' Event options
' blockSize = 1, so wait for 1 event to return
Dim options As New EventWatcherOptions( _
Nothing, TimeSpan.MaxValue, 1)
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher( _
"root\CIMV2", _
query, _
options)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Hemen arayan için tam güven. Bu üye kısmen güvenilen kod tarafından kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.