"Prisy" <Pr***@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
In asp.net(C#) we can get the Process Name of a process using the
following
code:
System.Diagnostics.Process item;
item.ProcessName.ToString();
Is there a way to get the User Name of a process?
--
Thanks
Prisy
Yep, using System.Management classes, here is how....
using System.Management;
using System.Diagnostics;
....
Process p = Process.GetCurrentProcess();
GetProcessIdentity(p.Id);
}
static void GetProcessIdentity(int Id)
{
using(ManagementObject process = new
ManagementObject("win32_process.handle=" + Id))
{
foreach (ManagementObject logonSession in
process.GetRelated("win32_logonSession"))
{
foreach(ManagementBaseObject account in
logonSession.GetRelated("win32_UserAccount"))
{
PropertyDataCollection processProperties = account.Properties;
Console.WriteLine("Name: {0} ,Domain: {1} ,Fullname: {2}, ,SID:
{3}" ,
processProperties["Name"].Value,
processProperties["Domain"].Value,
processProperties["FullName"].Value,
processProperties["SID"].Value);
}
}
}
}
Willy.