ManagementEventWatcher.Scope ManagementEventWatcher.Scope ManagementEventWatcher.Scope ManagementEventWatcher.Scope Property

정의

이벤트를 조사할 범위(네임스페이스 또는 범위)를 가져오거나 설정합니다.Gets or sets the scope in which to watch for events (namespace or scope).

public:
 property System::Management::ManagementScope ^ Scope { System::Management::ManagementScope ^ get(); void set(System::Management::ManagementScope ^ value); };
public System.Management.ManagementScope Scope { get; set; }
member this.Scope : System.Management.ManagementScope with get, set
Public Property Scope As ManagementScope

속성 값

이벤트를 조사할 범위입니다.The scope in which to watch for events.

예제

다음 예제에서는 클라이언트의 경우 인스턴스의 알림을 수신 하는 방법을 보여 줍니다 Win32_Process 이벤트 클래스 이므로 만들어집니다 __InstanceCreationEvent합니다.The following example shows how the client receives notification when an instance of Win32_Process is created because the event class is __InstanceCreationEvent. 자세한 내용은 WMI(Windows Management Instrumentation) 설명서를 참조 하세요.For more information, see the Windows Management Instrumentation documentation. 클라이언트에서는 WaitForNextEvent 메서드를 호출하여 이벤트를 동기적으로 수신합니다.The client receives events synchronously by calling the WaitForNextEvent method. 예제 코드가 실행될 때 메모장과 같은 프로세스를 시작하여 이 예제를 테스트할 수 있습니다.This example can be tested by starting a process, such as Notepad, while the example code is running.

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;
        watcher.Scope = new ManagementScope("root\\CIMV2");
        // 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
        watcher.Scope = New ManagementScope("root\CIMV2")
        ' 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

설명

속성 값Property Value

(네임 스페이스 또는 범위) 이벤트를 조사 하는 범위입니다.The scope in which to watch for events (namespace or scope).

.NET Framework 보안.NET Framework Security

직접 실행 호출자의 경우 완전히 신뢰합니다.Full trust for the immediate caller. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다.This member cannot be used by partially trusted code. 자세한 내용은 부분적으로 신뢰할 수 있는 코드에서 라이브러리를 사용 하 여입니다.For more information, see Using Libraries from Partially Trusted Code.

적용 대상