Query Process on a terminal server

G

Guest

Hi,

I want to allow users to start my application only once. To do so, I use

Process[] Processes = Process.GetProcessesByName("MyApp");

to get all processes running on the machine and compair to the current
process ID. This is OK for single user machines, however, it is not OK on a
terminal server.

The WIN32 way to solve this problem is to combine process information with
the session ID of the current user.

How do I get session information .NET / C#???

Thanx for help!
Hans.
 
W

Willy Denoyette [MVP]

| Hi,
|
| I want to allow users to start my application only once. To do so, I use
|
| Process[] Processes = Process.GetProcessesByName("MyApp");
|
| to get all processes running on the machine and compair to the current
| process ID. This is OK for single user machines, however, it is not OK on
a
| terminal server.
|
| The WIN32 way to solve this problem is to combine process information with
| the session ID of the current user.
|
| How do I get session information .NET / C#???
|
| Thanx for help!
| Hans.

The only reliable way to do this is by using a global mutex.
Following is a sample

bool okToRun;
// prevent multiple instances accross TS sessions by using a Global mutex
string uniqueAppId = "Global\\UniqueApplicationString";
using(Mutex m = new Mutex(true, uniqueAppId , out okToRun))
{
if (okToRun)
...
else
// other instance already running
}

Willy.
 
G

Guest

The answer is already given in this forum: check Willy Denoyette' answer on
"How to find users executing processes" .

Thanx for looking in anyway!
 
G

Guest

Hi Willy,

the app is allowed to run once per session rather than once per machine.
Yield the mutex solution would not work as the mutex is visible accross TS
session boundaries.

regards, Hans.
 
W

Willy Denoyette [MVP]

Make the Mutex non-global by removing 'Global' from the string, this
restricts the Mutex object to be 'visible' in the current session only.

Willy.

| Hi Willy,
|
| the app is allowed to run once per session rather than once per machine.
| Yield the mutex solution would not work as the mutex is visible accross TS
| session boundaries.
|
| regards, Hans.
|
| "Willy Denoyette [MVP]" wrote:
|
| >
| > | > | Hi,
| > |
| > | I want to allow users to start my application only once. To do so, I
use
| > |
| > | Process[] Processes = Process.GetProcessesByName("MyApp");
| > |
| > | to get all processes running on the machine and compair to the current
| > | process ID. This is OK for single user machines, however, it is not OK
on
| > a
| > | terminal server.
| > |
| > | The WIN32 way to solve this problem is to combine process information
with
| > | the session ID of the current user.
| > |
| > | How do I get session information .NET / C#???
| > |
| > | Thanx for help!
| > | Hans.
| >
| > The only reliable way to do this is by using a global mutex.
| > Following is a sample
| >
| > bool okToRun;
| > // prevent multiple instances accross TS sessions by using a Global
mutex
| > string uniqueAppId = "Global\\UniqueApplicationString";
| > using(Mutex m = new Mutex(true, uniqueAppId , out okToRun))
| > {
| > if (okToRun)
| > ...
| > else
| > // other instance already running
| > }
| >
| > Willy.
| >
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top