471,319 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Query Process on a terminal server

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.
Jan 24 '06 #1
4 3575

"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
| 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.
Jan 24 '06 #2
The answer is already given in this forum: check Willy Denoyette' answer on
"How to find users executing processes" .

Thanx for looking in anyway!

"Hans" 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.

Jan 24 '06 #3
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:

"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
| 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.

Jan 24 '06 #4
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.

"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
| 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:
|
| >
| > "Hans" <Ha**@discussions.microsoft.com> wrote in message
| > news:AA**********************************@microsof t.com...
| > | 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.
| >
| >
| >
Jan 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Markus Poehler | last post: by
5 posts views Thread by TPoise! | last post: by
4 posts views Thread by drodrig | last post: by
3 posts views Thread by Ben Finney | last post: by
14 posts views Thread by Simon Gare | last post: by
16 posts views Thread by =?Utf-8?B?RHdlZWJlcmVsbGE=?= | last post: by

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.