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
I was successful in getting events with process names and ids without admin privileges using the following query:
Unlike the query you were using, the event received doesn't have most of its properties filled.
However, they are accessible through the event's TargetInstance property.