Something like this ?
static void Main(string[] args) {
string[] arg = { "", "" };
ManagementScope scope = new ManagementScope(@"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from
Win32_Process");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();
foreach (ManagementObject process in processes) {
process.InvokeMethod("GetOwner", arg);
Console.WriteLine("caption = " + process["caption"] + "
owner = " + arg[1] + "\\" + arg[0]);
}
}
note you would just need the process id to only call it for a single process
Cheers,
Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:3A**********************************@microsof t.com...
Wow, brilliant, and it's not even new in VS2005!
Now - do you know how to get the user that a DIFFERENT process is running
under? I can do Process.GetProcesses() but a Process doesn't seem to
include
user info.
--
Dave
"Greg Young" wrote:
>WindowsPrincipal Principle = Thread.CurrentPrincipal as WindowsPrincipal;
Cheers,
Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microso ft.com...
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried
looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more
for
new
starting processes than examining the current one.
--
Dave