how to get the process owner after querying WMI ?

A

anna_incoming

Hello,

Using this sample code from MSDN, I would like to get the username of
processes which is started conform the WMI query.

I am not able to get username when calling GetOwner method of
ROOT.CIMV2.Process .

I know it would be something like this, but when I put in in the
EventHandler the function returns 0 which is correct but no
Username !!

App.ROOT.CIMV2.Process wmiProcess = new App.ROOT.CIMV2.Process(

(System.Management.ManagementBaseObject)e.NewEvent["TargetInstance"]);

and then: wmiProcess.GetOwner(out domain, out user); --> does not
work.


Pleeease can anyone help me with this ??????
I have tried a lot but I am quite new to dotnet/WMI.

Thank you in advance
Anna


/////// sample code

using System;
using System.Management;


public class EventWatcherAsync
{
public static int Main(string[] args)
{
WqlEventQuery query =
new WqlEventQuery("__InstanceCreationEvent",
new TimeSpan(0, 0, 1),
"TargetInstance isa \"Win32_Process\"");
ManagementEventWatcher watcher = new
ManagementEventWatcher(query);
watcher.EventArrived +=
new EventArrivedEventHandler((new
EventHandler()).HandleEvent);
watcher.Start();

System.Threading.Thread.Sleep(50000);

// Stop listening
watcher.Stop();
return 0;
}

}

public class EventHandler
{
public void HandleEvent(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Process has been created");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top