Re: UserName of a process
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Fri, 8 Jul 2005 22:27:01 +0200
"Prisy" <Prisy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F91E3EDA-9A5B-4659-9C49-025DFDE3231D@xxxxxxxxxxxxxxxx
> 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.
.
- References:
- UserName of a process
- From: Prisy
- UserName of a process
- Prev by Date: Re: getting multiple values returned from a method
- Next by Date: Re: Can i Box values in arrays
- Previous by thread: Re: UserName of a process
- Next by thread: ListView SelectedIndexChanged fires when e.Cancel set in Validatin
- Index(es):
Relevant Pages
|