473,566 Members | 3,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find users executing processes

Hi,

I am looking for a way to determine het user that is running a certain
process, I can retrieve the process ID by calling the
GetProcessByNam e("test") method which will return all processes named
'test'.
But how do I retrieve the user that is running the process ( the process
'test' is started using the 'run as ' function provided in the user
interface of windows)?

Any help would be appreciated,
Han


Jan 13 '06 #1
2 4295

"Han de Monnink" <ha************ @hp.com> wrote in message
news:dq******** **@news4.zwoll1 .ov.home.nl...
| Hi,
|
| I am looking for a way to determine het user that is running a certain
| process, I can retrieve the process ID by calling the
| GetProcessByNam e("test") method which will return all processes named
| 'test'.
| But how do I retrieve the user that is running the process ( the process
| 'test' is started using the 'run as ' function provided in the user
| interface of windows)?
|
| Any help would be appreciated,
|
|
| Han
|
|
|
|

You can use System.Manageme nt and WMI for this. Just query the process list
using one of the process properties as serch criteria and call WMI's
GetOwner method on the instances returned.
Folling illustrates the process using a process name as query property.

GetProcessOwner ("some.exe") ;

....
private static void GetProcessOwner (string procName)
{
SelectQuery selectQuery = new SelectQuery("se lect * from Win32_Process
where name='" + procName + "'");
using(Managemen tObjectSearcher searcher = new
ManagementObjec tSearcher(selec tQuery))
{
ManagementObjec tCollection processes = searcher.Get();
foreach(Managem entObject process in processes)
{
//out argument to return user and domain
string[] s = new String[2];
//Invoke the GetOwner method and populate the array with the user
name and domain
process.InvokeM ethod("GetOwner ",(object[])s);
Console.WriteLi ne("User: " + s[1]+ "\\" + s[0]);
}
}
}
}

Willy.
Jan 13 '06 #2
Thanks,

I tried it and it seems to work Great ...
Han
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..

"Han de Monnink" <ha************ @hp.com> wrote in message
news:dq******** **@news4.zwoll1 .ov.home.nl...
| Hi,
|
| I am looking for a way to determine het user that is running a certain
| process, I can retrieve the process ID by calling the
| GetProcessByNam e("test") method which will return all processes named
| 'test'.
| But how do I retrieve the user that is running the process ( the
process
| 'test' is started using the 'run as ' function provided in the user
| interface of windows)?
|
| Any help would be appreciated,
|
|
| Han
|
|
|
|

You can use System.Manageme nt and WMI for this. Just query the process
list
using one of the process properties as serch criteria and call WMI's
GetOwner method on the instances returned.
Folling illustrates the process using a process name as query property.

GetProcessOwner ("some.exe") ;

...
private static void GetProcessOwner (string procName)
{
SelectQuery selectQuery = new SelectQuery("se lect * from
Win32_Process
where name='" + procName + "'");
using(Managemen tObjectSearcher searcher = new
ManagementObjec tSearcher(selec tQuery))
{
ManagementObjec tCollection processes = searcher.Get();
foreach(Managem entObject process in processes)
{
//out argument to return user and domain
string[] s = new String[2];
//Invoke the GetOwner method and populate the array with the user
name and domain
process.InvokeM ethod("GetOwner ",(object[])s);
Console.WriteLi ne("User: " + s[1]+ "\\" + s[0]);
}
}
}
}

Willy.

Jan 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
17613
by: Tim Morrison | last post by:
SQL Server 2000 - MSDE 2000 Is there a way to get the number of current users logged into a SQL 2000 Server (also MSDE)? Cant be distinct users as most users are logged into the database using the same login. -- Tim Morrison -------------------------------------------------------------------------------- Vehicle Web Studio - The...
13
2822
by: BK | last post by:
Can someone point me to a code sample that illustrates executing long running tasks (asynchronous) from a web application in ASP.NET? I assume that Web Services might come into play at some point, but I'm not sure how to get started. For example, I have an application that, upon a user initiating through a button or link click, will go out...
1
4301
by: DD | last post by:
I'm not sure that this msg made it out, the first time I sent it, so I am trying again. -- Win XP Home Edition I use System.Diagnostics.Process.GetProcesses()) to get info about the processes running. I don't see any members of class' Process' which allows me to get the name of the owner of the process.
15
2124
by: Chakkaradeep | last post by:
Hi all, i have written a Service,now i want to execute another application (for eg;calc.exe) in the service....how will i perform it??... i tried using this.... /**************Executing a Process code starts here**************/ System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false;
1
1028
by: Jason | last post by:
I've tried executing processes under Visual Basic.NET-based Windows services in the past but to no avail. Is it possible to execute a process via System.Diagnostics in a Windows Service? The user does not have to be able to interact with the process, but let's say the (hidden) process does a file conversion. I'd like to be able to execute...
8
3102
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are initialized before the program starts executing." -- What does this mean? What is the name of the stage in which the mentioned initialization is...
0
1277
by: Jorre Meijrink | last post by:
Dear reader, We have two Win2003 webfarms each consisting of 5 servers. Which we call cluster1 and cluster2. Cluster2 is the bussiest of these two and periodicaly (varies from 2 times per day to two times per week) one of the servers (this is pretty random) starts to build up Requests Executing. During this 'queueing' it still serves about...
2
7132
by: Gary | last post by:
Hi i need to work with windows of processes that are running on my pc from a certain programme. I've figured out how to build an array of processes that contain just the processes i'm interested in by checking what the process name starts with. How do i find out the hWnd for the processes i've returned, because the function i need to run...
3
2911
by: evenrik | last post by:
An a redhat box I have root, apache and other normal users run code that uses the logging module to write to the same log file. Since umasks are set to 2 or 022 this gets permission errors. I have fixed my issue by patching the logging code everywhere there is an open for write with: try: old_umask = os.umask(0) # open for write here...
0
7586
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8113
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7649
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6270
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5487
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5215
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.