473,406 Members | 2,705 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,406 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 3719

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
0
by: Markus Poehler | last post by:
Hi my program should run on terminal server. I open Acrobat process and I have to kill them at some points in my application. This fails cause of insufficient rights on terminal server. the...
5
by: TPoise! | last post by:
Using: .NET 1.1, Visual Studio 2003, C#, Microsoft Windows 2000 Server (SP4 and all latest windows updates), Terminal Server running in application mode. I have a C# application that I've...
6
by: Atley | last post by:
I have a Terminal Services server running Windows 2000 Server. I need to be able to identify, in my application on that server, which client computer is addressing that server and running that...
11
by: Tore Halset | last post by:
Hello. I am trying to port an old java application from MS SQL Server to PostgreSQL running on Mac OS X. I have access to the java source code and can make modifications. I have tried with...
4
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which...
3
by: Ben Finney | last post by:
Howdy all, For making a Python program calve off an independent daemon process of itself, I found Carl J. Schroeder's recipe in the ASPN Python Cookbook....
14
by: Simon Gare | last post by:
Hi, have a search.asp page with results.asp page drawing data from an SQL db, problem is the user has to type the whole field value into the search box to retrieve the value on results.asp, what...
16
by: =?Utf-8?B?RHdlZWJlcmVsbGE=?= | last post by:
I created an Access 2007 application for my customer. The application is shared by three employees on a server. It maintains a contact list including financial data and social security numbers. ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.