2

I have a piece of code to handle scenarios where specific processes are started or stopped and in order to achieve this I am using ManagementEventWatcher.

       string queryStart = "SELECT * FROM Win32_ProcessStartTrace" +
                     " WHERE ProcessName LIKE '...'"; // WHERE clause includes all the processnames that I want to monitor 
       ManagementEventWatcher startWatch = new ManagementEventWatcher(
            new WqlEventQuery(queryStart));
        startWatch.EventArrived += new EventArrivedEventHandler(ProcessNewInstanceWhenCreated);
        startWatch.Start();

This code works fine locally on my machine but when I deploy it to one of the servers it throw "Access denied" exception. The user running this on the server does not have admin rights and accordingly I added the user as explained in this link - http://world.episerver.com/faq/Items/SystemManagementManagementException-Access-denied/

This doesnt seem to solve the problem. Do I have perform any other action to get this to work on the server?

I added a ManagementScope to the ManagementEventHandler as well but still doesnt help the cause.

       string scopeString = "\\\\" + System.Environment.MachineName + "\\root\\CIMV2";
        ManagementScope theScope = new ManagementScope(scopeString);
        ManagementEventWatcher startWatch = new ManagementEventWatcher(theScope,
            new WqlEventQuery(queryStart));

Thank you for your time and help

Tsst
  • 61
  • 8
  • Spying on starting processes is a security risk, the program must run elevated. Add the [required manifest](http://stackoverflow.com/a/2818776/17034). – Hans Passant Aug 04 '15 at 08:32

0 Answers0