Re: UserName of a process




"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.


.



Relevant Pages

  • Re: reading a directory, first files the newest ones
    ... jordilin wrote: ... foreach my $file { ... With this code, and taking into account that the directory is huge, ... through a while till we get the proper files, ...
    (comp.lang.perl.misc)
  • Re: Lines in a text file
    ... (Did you account for the CrLf characters? ... LFS ... Prev by Date: ...
    (microsoft.public.vb.general.discussion)
  • Re: weaving info sought
    ... > This practice has cut my spam by more than 95%. ... I did have to abandon a perfectly good email account... ... Prev by Date: ...
    (rec.crafts.textiles.yarn)
  • Re: Anyone had one of these from Paypal???????????
    ... > They do not ask me to log in through a link on the email so I presume it ... > If so what information do you need to provide when you go to account ... Peter Crosland ... Prev by Date: ...
    (uk.people.consumers.ebay)
  • Exchange 2003 SBS and Outlook 2003
    ... goes into the sent items, but the recepient never receives the email, and ... and 'bcc' fields. ... account. ... Prev by Date: ...
    (microsoft.public.exchange2000.misc)