By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

how to get the process owner after querying WMI ?

P: n/a
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");
}
}

Feb 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you asked the question i wanted to. but it see no answers have come forward.
so i searched on the web and found this article and have yet digested. maybe
this will help you:
http://www.codeproject.com/useritems...ssownersid.asp
"How to get process owner ID and current user SID"
"an***********@hotmail.com" wrote:
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");
}
}

Feb 20 '07 #2

P: n/a
On Feb 20, 7:20 am, auldh <a...@discussions.microsoft.comwrote:
you asked the question i wanted to. but it see no answers have come forward.
so i searched on the web and found this article and have yet digested. maybe
this will help you:http://www.codeproject.com/useritems...ssownersid.asp
"How to get process owner ID and current user SID"
yes, thank you ! I have found it too and is working perfectly !
Greetings
Anna

Mar 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.