2

Why do I get The type or namespace name 'ManagementEventWatcher' not found in the following code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Management;

class Program {
    public ManagementEventWatcher mgmtWtch;

    static void Main(string[] args)
    {
        InitializeComponent();
        mgmtWtch = new System.Management
                     .ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
        mgmtWtch.EventArrived += new    
            System.Management.EventArrivedEventHandler(mgmtWtch_EventArrived);
        mgmtWtch.Start();
    }
}

I think my dll doesn't have this method, but how to check?

Kev
  • 118,037
  • 53
  • 300
  • 385
red eyes dev
  • 398
  • 3
  • 11

2 Answers2

5

Have you added the reference as well as the using? eg

using System.Management;

is not enough.. you need to add the reference to System.Management too.

BugFinder
  • 17,474
  • 4
  • 36
  • 51
0

Your Main method is static, but your mgmWtch variable is not. Declare it as as static.

jlew
  • 10,491
  • 1
  • 35
  • 58