473,406 Members | 2,713 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.

Ensure that only on app instance is running per user ts session

Hi,

I'd like to make sure that only one instance of my app is running per User
Session. In addition this has to work with user rights and in a Windows
2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio
Nov 21 '05 #1
6 9466
Hi,

Use a mutex instead

http://www.vb-tips.com/default.aspx?...6-343ac05a7617

Ken
-------------------
"Xenio" <so***********@xenio-dev.com> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'd like to make sure that only one instance of my app is running per User
Session. In addition this has to work with user rights and in a Windows
2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a
TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio

Nov 21 '05 #2
Check the PrevInstance property of the App Object to find out if any more
instance of your application is running, this works in VB6 but in fact I
don't know if the App object is still in VB.net.

"Xenio" wrote:
Hi,

I'd like to make sure that only one instance of my app is running per User
Session. In addition this has to work with user rights and in a Windows
2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio

Nov 21 '05 #3
Check the PrevInstance property of the App Object to find out if any more
instance of your application is running, this works in VB6 but in fact I
don't know if the App object is still in VB.net.
well it isn`t ( so you crashed and burned ) :-)

so the TS used the correct .Net 2003 substitute (
"Process.GetProcessesByName(thisProcess.ProcessNam e)")

however i guess this will fail in a Terminal server / Citrix context as
there the TS wants to have the ability to start multiple instances however
all in a seperate user context ( if i understood the question correct )

regards

Michel Posseth

"Hillinsilence" <Hi***********@discussions.microsoft.com> schreef in bericht
news:61**********************************@microsof t.com... Check the PrevInstance property of the App Object to find out if any more
instance of your application is running, this works in VB6 but in fact I
don't know if the App object is still in VB.net.

"Xenio" wrote:
Hi,

I'd like to make sure that only one instance of my app is running per
User
Session. In addition this has to work with user rights and in a Windows
2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a
TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio

Nov 21 '05 #4

Are you sure ???

I do not believe that a mutex is a solution in this case

Afaik the proggy will still see multiple instances in this case , as the
TS wants to have the ability to start multiple instances of his / her app
however they must then be running on a different user account in Terminal
server / Citrix
I guess that the only solution i see so far in this situation , is to create
your own ticket system
Or i am completely missing something here ( could be ) that a mutex will
only be vissible in the current users context , however in this situation it
would not be usable for a server app ( so i don`t think so ) .

I guess this could become a interesting topic......

regards

Michel Posseth [MCP]



"Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht
news:et**************@tk2msftngp13.phx.gbl...
Hi,

Use a mutex instead

http://www.vb-tips.com/default.aspx?...6-343ac05a7617

Ken
-------------------
"Xenio" <so***********@xenio-dev.com> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'd like to make sure that only one instance of my app is running per
User Session. In addition this has to work with user rights and in a
Windows 2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a
TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio


Nov 21 '05 #5
:-)

FindWindow will return a valid handle if it finds the window class in the
current active session (desktop).
While using a mutex will prevent the user to start an application allready
running in another session.

yeahh i know using FindWindow is bad .... but euhh does anyone has a better
suggestion , to detect if someone trys to s art multiple instances of an app
in a users context ??

so a app might be started multiple times , however then under different user
accounts ( like on TS systems )
regards

Michel Posseth [MCP]
"m.posseth" <po*****@planet.nl> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl...

Are you sure ???

I do not believe that a mutex is a solution in this case

Afaik the proggy will still see multiple instances in this case , as the
TS wants to have the ability to start multiple instances of his / her app
however they must then be running on a different user account in Terminal
server / Citrix
I guess that the only solution i see so far in this situation , is to
create your own ticket system
Or i am completely missing something here ( could be ) that a mutex will
only be vissible in the current users context , however in this situation
it would not be usable for a server app ( so i don`t think so ) .

I guess this could become a interesting topic......

regards

Michel Posseth [MCP]



"Ken Tucker [MVP]" <vb***@bellsouth.net> schreef in bericht
news:et**************@tk2msftngp13.phx.gbl...
Hi,

Use a mutex instead

http://www.vb-tips.com/default.aspx?...6-343ac05a7617

Ken
-------------------
"Xenio" <so***********@xenio-dev.com> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'd like to make sure that only one instance of my app is running per
User Session. In addition this has to work with user rights and in a
Windows 2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a
TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio



Nov 21 '05 #6
well i have been playing with that mutex thingy

and this seems to be the solution, for your Terminal server problem

call it on start of your application with usercontex = true to support
multiple instances that run on a different user contex
call it on start of your application with usercontex = false to support only
one instance
Imports System.Threading

Private oMutex As Mutex

Private Function InstanceRunning(ByVal UserContex As Boolean) As Boolean

Dim progid As String = "{4C91B499-109B-42c8-B68E-E125F321EED6}" ' change the
id for every app you deploy ( tools ,create guid )

oMutex = New Mutex(False, String.Concat(progid, CStr(IIf(UserContex,
System.Environment.UserName, ""))))

If oMutex.WaitOne(0, False) = False Then

oMutex.Close()

Return True

End

End If
End Function

am i the only one who found this a verry interesting topic / task

regards

Michel Posseth [MCP]


"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:et**************@tk2msftngp13.phx.gbl...
Hi,

Use a mutex instead

http://www.vb-tips.com/default.aspx?...6-343ac05a7617

Ken
-------------------
"Xenio" <so***********@xenio-dev.com> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'd like to make sure that only one instance of my app is running per
User Session. In addition this has to work with user rights and in a
Windows 2k/2k3 and Citrix Terminalserver environment.

The code I'm using prevents the app from creating a second instance on a
TS.

What do I have to change?

Dim handler As ThreadExceptionHandler = New ThreadExceptionHandler
AddHandler Application.ThreadException, AddressOf
handler.Application_ThreadException

Dim findProcesses(), thisProcess As Process

thisProcess = Process.GetCurrentProcess()

findProcesses = Process.GetProcessesByName(thisProcess.ProcessName )
If findProcesses.Length = 1 Then
Dim aForm As New myForm
Application.Run(aForm)
End If

Thanks in advance for any hint

Xenio


Nov 21 '05 #7

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

Similar topics

5
by: FLEB | last post by:
I'm working on a logon system, something generic and modular, as a part of a few ideas I have running. I'm just wondering, though, what is the best way to keep a user logged in authentically...
6
by: Dmitry Karneyev | last post by:
Hi! I guess this question have been asked a lot of times, but please be tolerant and if you have any ideas share it. The question is: how to make availibale only one instance of application and...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
8
by: Li Pang | last post by:
Hi I want to run my app only one instance, i.e. only one session is allowed to display Thank
1
by: anonieko | last post by:
Problem When Remote Desktop to my main office machine, and when trying to connect to SQL Express, I was becoming increasingly frustrated with the following error: Error: 'Failed to generate a...
16
by: Ben Sehara | last post by:
Is there any way I can limit the access to my website? I have a site "A" and I want to allow access to it only from site "B" login user. If someone try to access site "A" directory, I want it...
20
by: Boki Digtal | last post by:
Hi All, How to limit the c# program can only run one instance at the same time ? Thank you! Best regards, Boki.
11
by: Flexor | last post by:
I have a php script that runs from command line and makes an https request to paypal, using curl. It works fine if I run it from a web page. It fails if I run it from CLI. The error I get from...
4
by: Timothy Grant | last post by:
On Fri, Aug 29, 2008 at 6:51 AM, Heston James <heston_james@live.co.ukwrote: Why not look at the process list, and if you find two entries kill the one that is just starting? -- Stand Fast,...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.