finding out the username of a process
- From: amirzaee@xxxxxxxxx
- Date: 21 Oct 2006 11:45:49 -0700
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.
.
- Prev by Date: Re: Monitoring CPU Temperature and Fan speed
- Next by Date: Re: Using WMI from Within a service.
- Previous by thread: Re: Monitoring CPU Temperature and Fan speed
- Next by thread: 0 results from wbemtest
- Index(es):
Relevant Pages
|
Loading