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

  • Thread starter Thread starter Xenio
  • Start date Start date
X

Xenio

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
 
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.
 
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
 
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]
 
:-)

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 said:
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 said:
 
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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top