473,581 Members | 3,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetProc essesByName("My App");

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 3733

"Hans" <Ha**@discussio ns.microsoft.co m> wrote in message
news:AA******** *************** ***********@mic rosoft.com...
| Hi,
|
| I want to allow users to start my application only once. To do so, I use
|
| Process[] Processes = Process.GetProc essesByName("My App");
|
| 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\\Unique ApplicationStri ng";
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.GetProc essesByName("My App");

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**@discussio ns.microsoft.co m> wrote in message
news:AA******** *************** ***********@mic rosoft.com...
| Hi,
|
| I want to allow users to start my application only once. To do so, I use
|
| Process[] Processes = Process.GetProc essesByName("My App");
|
| 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\\Unique ApplicationStri ng";
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**@discussio ns.microsoft.co m> wrote in message
news:98******** *************** ***********@mic rosoft.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**@discussio ns.microsoft.co m> wrote in message
| > news:AA******** *************** ***********@mic rosoft.com...
| > | Hi,
| > |
| > | I want to allow users to start my application only once. To do so, I
use
| > |
| > | Process[] Processes = Process.GetProc essesByName("My App");
| > |
| > | 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\\Unique ApplicationStri ng";
| > 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
5213
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 includes the following columns: DocID (INTEGER, PRIMARY KEY, CLUSTERED) IsRecord (INTEGER, NONCLUSTERED)
0
3322
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 lines: Dim p As New Process For Each p In Process.GetProcesses If LCase(p.ProcessName) = "acrord32" Then 'p.Kill()
5
7566
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 deployed to our terminal server for remote users to use. However, normal users (simple domain users) can not run the application. After double...
6
4034
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 application. it can be by IP or by machine network name... Doesn't matter. I am using Visual Basic .Net 2003 Any help would be greatly...
11
6639
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 PostgreSQL version 7.4.2 and 8.0.0beta2, but get the same error. I am using pgdev.305.jdbc3.jar for 8.0.0beta2. The PostgreSQL installation are standard,...
4
17440
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 windows are visible, then send a WM_CLOSE message to the window to request that it closes. Of course, not all apps want to close nicely. At this...
3
6187
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. <URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731> This is a thorough approach, and I'm cribbing a simpler process from this example. One thing that strikes me is that...
14
2252
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 I need is to type in just a few characters e.g. at the moment to search for all pickups at Heathrow Terminal 1 the user has to type in Heathrow...
16
3984
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. Only the office manager generates reports in Access from this client data. Now they want to share this Access application with employees at a...
0
7788
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
8166
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
6546
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
5667
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
5357
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...
0
3799
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1398
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1127
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.