Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

25 views
Skip to first unread message

Xenio

unread,
Oct 31, 2005, 5:46:44 AM10/31/05
to
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


Ken Tucker [MVP]

unread,
Oct 31, 2005, 6:17:22 AM10/31/05
to
Hi,

Use a mutex instead

http://www.vb-tips.com/default.aspx?ID=59135549-e5dd-4501-9526-343ac05a7617

Ken
-------------------
"Xenio" <softwa...@xenio-dev.com> wrote in message
news:eYaakhg3...@TK2MSFTNGP12.phx.gbl...

Hillinsilence

unread,
Oct 31, 2005, 6:24:02 AM10/31/05
to
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.

m.posseth

unread,
Oct 31, 2005, 10:38:02 AM10/31/05
to

> 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.ProcessName)")

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" <Hillin...@discussions.microsoft.com> schreef in bericht
news:61FDF13F-7839-45F3...@microsoft.com...

m.posseth

unread,
Oct 31, 2005, 10:45:44 AM10/31/05
to

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:et9Nuyg3...@tk2msftngp13.phx.gbl...

m.posseth

unread,
Nov 1, 2005, 12:01:13 PM11/1/05
to
:-)

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" <pos...@planet.nl> wrote in message
news:O1AElIj...@TK2MSFTNGP10.phx.gbl...

m.posseth

unread,
Nov 1, 2005, 12:41:36 PM11/1/05
to
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:et9Nuyg3...@tk2msftngp13.phx.gbl...

0 new messages