ManagementEventWatcher 생성자

정의

ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
ManagementEventWatcher()

ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다. 추가 초기화를 위해 개체의 속성을 설정합니다. 매개 변수가 없는 생성자입니다.

ManagementEventWatcher(EventQuery)

WMI ManagementEventWatcher가 제공되면 클래스의 새 인스턴스를 초기화합니다.

ManagementEventWatcher(String)

WMI ManagementEventWatcher 문자열 형식으로 지정하면 클래스의 새 인스턴스를 초기화합니다.

ManagementEventWatcher(ManagementScope, EventQuery)

지정된 WMI ManagementEventWatcher 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다.

ManagementEventWatcher(String, String)

지정된 WMI ManagementEventWatcher 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다. 이 변형의 경우 쿼리와 범위가 문자열로 지정됩니다.

ManagementEventWatcher(ManagementScope, EventQuery, EventWatcherOptions)

지정된 옵션에 ManagementEventWatcher 따라 지정된 WMI 이벤트 쿼리를 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다. 이 변형의 경우 쿼리와 범위가 지정된 개체입니다. options 개체는 제한 시간 및 컨텍스트 정보와 같은 옵션을 지정할 수 있습니다.

ManagementEventWatcher(String, String, EventWatcherOptions)

지정된 옵션에 ManagementEventWatcher 따라 지정된 WMI 이벤트 쿼리를 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다. 이 변형의 경우 쿼리와 범위가 문자열로 지정됩니다. options 개체는 제한 시간 및 컨텍스트 정보와 같은 옵션을 지정할 수 있습니다.

ManagementEventWatcher()

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다. 추가 초기화를 위해 개체의 속성을 설정합니다. 매개 변수가 없는 생성자입니다.

public:
 ManagementEventWatcher();
public ManagementEventWatcher();
Public Sub New ()

예제

다음 예제에서는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 클라이언트가 알림을 받는 방법을 보여 줍니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ManagementEventWatcher(EventQuery)

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

WMI ManagementEventWatcher가 제공되면 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

query
EventQuery

EventQuery 감시자가 수신 대기할 이벤트를 결정하는 WMI 이벤트 쿼리를 나타냅니다.

예제

이 코드 예제에서 클라이언트는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 알림을 받습니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

감시자가 이벤트를 수신 대기하는 네임스페이스는 현재 설정된 기본 네임스페이스입니다.

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ManagementEventWatcher(String)

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

WMI ManagementEventWatcher 문자열 형식으로 지정하면 클래스의 새 인스턴스를 초기화합니다.

public:
 ManagementEventWatcher(System::String ^ query);
public ManagementEventWatcher(string query);
new System.Management.ManagementEventWatcher : string -> System.Management.ManagementEventWatcher
Public Sub New (query As String)

매개 변수

query
String

감시자가 수신 대기할 이벤트를 정의하는 WMI 이벤트 쿼리입니다.

예제

다음 예제에서는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 클라이언트가 알림을 받는 방법을 보여 줍니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

감시자가 이벤트를 수신 대기하는 네임스페이스는 현재 설정된 기본 네임스페이스입니다.

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ManagementEventWatcher(ManagementScope, EventQuery)

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

지정된 WMI ManagementEventWatcher 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

scope
ManagementScope

ManagementScope 감시자가 이벤트를 수신 대기할 범위(네임스페이스)를 나타내는 값입니다.

query
EventQuery

EventQuery 감시자가 수신 대기할 이벤트를 결정하는 WMI 이벤트 쿼리를 나타냅니다.

예제

이 코드 예제에서 클라이언트는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 알림을 받습니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ManagementEventWatcher(String, String)

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

지정된 WMI ManagementEventWatcher 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다. 이 변형의 경우 쿼리와 범위가 문자열로 지정됩니다.

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)

매개 변수

scope
String

감시자가 이벤트를 수신 대기하는 관리 범위(네임스페이스)입니다.

query
String

감시자가 수신 대기할 이벤트를 정의하는 쿼리입니다.

예제

다음 예제에서는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 클라이언트가 알림을 받는 방법을 보여 줍니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ManagementEventWatcher(ManagementScope, EventQuery, EventWatcherOptions)

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

지정된 옵션에 ManagementEventWatcher 따라 지정된 WMI 이벤트 쿼리를 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다. 이 변형의 경우 쿼리와 범위가 지정된 개체입니다. options 개체는 제한 시간 및 컨텍스트 정보와 같은 옵션을 지정할 수 있습니다.

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)

매개 변수

scope
ManagementScope

ManagementScope 감시자가 이벤트를 수신 대기할 범위(네임스페이스)를 나타내는 값입니다.

query
EventQuery

EventQuery 감시자가 수신 대기할 이벤트를 결정하는 WMI 이벤트 쿼리를 나타냅니다.

options
EventWatcherOptions

EventWatcherOptions 이벤트를 감시하는 데 사용되는 추가 옵션을 나타냅니다.

예제

다음 예제에서는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 클라이언트가 알림을 받는 방법을 보여 줍니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ManagementEventWatcher(String, String, EventWatcherOptions)

Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs
Source:
ManagementEventWatcher.cs

지정된 옵션에 ManagementEventWatcher 따라 지정된 WMI 이벤트 쿼리를 따르는 이벤트를 수신 대기하는 클래스의 새 인스턴스를 초기화합니다. 이 변형의 경우 쿼리와 범위가 문자열로 지정됩니다. options 개체는 제한 시간 및 컨텍스트 정보와 같은 옵션을 지정할 수 있습니다.

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)

매개 변수

scope
String

감시자가 이벤트를 수신 대기하는 관리 범위(네임스페이스)입니다.

query
String

감시자가 수신 대기할 이벤트를 정의하는 쿼리입니다.

options
EventWatcherOptions

EventWatcherOptions 이벤트를 감시하는 데 사용되는 추가 옵션을 나타냅니다.

예제

다음 예제에서는 이벤트 클래스가 __InstanceCreationEvent 때문에 Win32_Process 인스턴스를 만들 때 클라이언트가 알림을 받는 방법을 보여 줍니다. 자세한 내용은 Windows Management Instrumentation 설명서를 참조하세요. 클라이언트는 메서드를 호출하여 이벤트를 동기적으로 수신합니다 WaitForNextEvent . 이 예제는 예제 코드가 실행되는 동안 메모장과 같은 프로세스를 시작하여 테스트할 수 있습니다.

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

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상