473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Get owner of a process

Hi

I am writing a program for a terminalserver.
But the program should startet only once
so i write a methode which returns if the process is running:
....
Process[] processes = Process.GetProcessesByName(ProcessName);

if(processes.Length > 1)
{
return true;

}
else
{
return false;
}
....

so now me problem.

I want that every user on the terminalservice can start the program once!

But when sameone starts it a other user can't start it too!

so i must check the user of the process.
who can i get the owner of the process?

thx

greets tim
Nov 16 '05 #1
1 4181
Hi Tim:

What you want to create is a 'named mutex' with the
System.Threading.Mutex class. I believe the documentation even has a
sample demonstrating how to ensure only one instance of an application
is running.

A Mutex is a kernel object and goes into a 'namespace' for the
terminal service session (not to be confused with .Net namespaces -
it's a kernel object namespace which prevents naming conflicts just
like a .NET namespace). This means it prevents multiple instances of
the application from running in the *same* terminal services session.

Just in case you wanted only one instance of the application for the
entire machine, you can put the Mutex in the global namespace by
prefixing the name with 'Global\'.

You'll find this approach to be more robust then searching through the
process list.

HTH,

--
Scott
http://www.OdeToCode.com

On 18 Aug 2004 00:57:33 -0700, tb*@uni.de (Tim B) wrote:
Hi

I am writing a program for a terminalserver.
But the program should startet only once
so i write a methode which returns if the process is running:
...
Process[] processes = Process.GetProcessesByName(ProcessName);

if(processes.Length > 1)
{
return true;

}
else
{
return false;
}
...

so now me problem.

I want that every user on the terminalservice can start the program once!

But when sameone starts it a other user can't start it too!

so i must check the user of the process.
who can i get the owner of the process?

thx

greets tim


Nov 16 '05 #2

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

Similar topics

1
by: ravi | last post by:
Hello everyone, Could any one tell me how to find the username(owner name) from a process handle or a process ID. ? thank you for your help Ravi
0
by: Durval Mateus | last post by:
Hello, I need to know the owner of a process, but the process class does not have that info. How can i retrieve the owner info? thanks in advance, Durval Mateus
1
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...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
7
by: Dave Coate | last post by:
Hi everyone, I am looking for a way to 'override' file security and read the Owner of a file to which I have no access. I am a system administrator, as such I have administrative rights to all...
3
by: Dave Coate | last post by:
Hello again, I am going to re-post a question. I got some excellent suggestions from Rob and Mattias on this but their ideas did not solve the problem. Here is the original post: ...
2
by: levimc | last post by:
I know that that topic may be old to you but I looked at other more- than-two-year-old topics related to mine. However, I didn't find them working for my project at all because its errors return...
1
by: Vishal Sethia | last post by:
Just trying to understand the behaviour of spawn. Consider I have a function which creates two threads. And in one of the threads I make a call to pexpect.spawn. spawn would fork and create a new...
2
by: stefan.albert | last post by:
Hello Ravi, what you want to do is very tricky, but possible. I've had this same problem - we want to identify the top user of tempspace and eventually force him off when using too much space (FS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.