finding out the username of a process



Hi Guys,

I am trying to find out the username, under which, a process is being
run. Here is the code that I am using, which partially came from
material I found under another post:

=======================

public void is_running()
{
System.Diagnostics.Process[] process_list =
System.Diagnostics.Process.GetProcesses(".");

foreach (System.Diagnostics.Process proc in process_list)
{
Process p = Process.GetProcessById(proc.Id);

ManagementObject process = new
ManagementObject("win32_process.handle=" + p.Id);
{
foreach (ManagementObject logonSession in
process.GetRelated("win32_logonSession"))
{
foreach (ManagementBaseObject account in
logonSession.GetRelated("win32_UserAccount"))
{
PropertyDataCollection
processProperties = account.Properties;
RTB1.Text +=
processProperties["Name"].Value.ToString() + "\n";
}
}
}
}
}

============

In this code, RTB1 is just a rich text box that will display what user
is running each process. Now, the problem is, I am able to see the
username associated with the processes that are running under the
username, under which, I am currently logged on to.

In other words, if I run this program from a certain account, I will
only be able to view the username of processes running under this very
same account. I cannot see the usernames associated with processes that
are running under a different username.

Is there something I am doing wrong?

I would appreciate any help...

Thank you so much,
Aydin.

.



Relevant Pages

  • pushing csv vaules into hash
    ... I need to split values from a csv value and push ... then perform a routine for all of them in a foreach ... address with the message containing their username and password. ... through them with once they are in the array, but then how do I get them ...
    (perl.beginners)
  • Re: pushing csv vaules into hash
    ... then perform a routine for all of them in a foreach ... address with the message containing their username and password. ... successful in reading the lines of the file and the ability to iterate ... through them with once they are in the array, but then how do I get them ...
    (perl.beginners)
  • Re: pushing csv vaules into hash
    ... pushing csv vaules into hash ... then perform a routine for all of them in a foreach ... address with the message containing their username and password. ... through them with once they are in the array, but then how do I get them ...
    (perl.beginners)
  • Re: PWDUMP Parser
    ... I need to extract ... A quick Perl script would do it for you...the below script takes a username as an arguement and dumps the username/hash pair to a file. ... foreach my $line { ...
    (Pen-Test)
  • Net::FTP: cwd( )
    ... I can connect all right, but the $ftp->cwd, while succeeding, only moves me to /, rather than into the directory. ... my $username = 'anonymous'; ... foreach { ... If failure had no penalty success would not be a prize ...
    (comp.lang.perl.misc)

Loading