Single instance application

  • Thread starter Thread starter Marco
  • Start date Start date
M

Marco

I should mention that this is for VB2003.

I need to make sure that only one instance of my application is running at a
time. I already have some code that does this and it does work but I ran
into a problem. Here is the code. It returns true if the application is
already running.

If
UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName))
Return True
Else
Return False
End If

The code is simple and it works great ... at least until you have more then
one user logged in at once. This was never an issue until now. What's
happening is that the software has been installed in a public computer where
a few people will be using it per day. Instead of logging on and off all
the time they were told to stay logged in and use the windows key + L to go
back to the login screen when they are done. In this scenario you will have
2 different users opening up the same software in the same computer under
different user accounts. The problem with the code is that it checks all of
the processes for the same name instead of the just the ones that belong to
the logged in user. I've tried to get it to check by user only but could
not find a solution. Is it possible to do that or do I have to use a new
way to check if the application is already running? If so can someone point
me in the right direction? Thanks.
 
Marco said:
I should mention that this is for VB2003.

I need to make sure that only one instance of my application is running at a
time. I already have some code that does this and it does work but I ran
into a problem. Here is the code. It returns true if the application is
already running.

If
UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName))
Return True
Else
Return False
End If

The code is simple and it works great ... at least until you have more then
one user logged in at once. This was never an issue until now. What's
happening is that the software has been installed in a public computer where
a few people will be using it per day. Instead of logging on and off all
the time they were told to stay logged in and use the windows key + L to go
back to the login screen when they are done. In this scenario you will have
2 different users opening up the same software in the same computer under
different user accounts. The problem with the code is that it checks all of
the processes for the same name instead of the just the ones that belong to
the logged in user. I've tried to get it to check by user only but could
not find a solution. Is it possible to do that or do I have to use a new
way to check if the application is already running? If so can someone point
me in the right direction? Thanks.

One way to do this, and I'm not positive it's the easiest is to use
remoting. Take a look at this article.

http://www.codeproject.com/vb/net/sing_inistan.asp

Chris
 
Marco,
After long discussions probably the best.

Have a look for it on our website.

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

I hope this helps,

Cor

I was about to recommend a mutex on the form as well. I have a write-up and
sample application which works in a Terminal Services environment which should
work similarly to the fast user switching mode in Win XP. The code sample
includes a number of helpful links as well. It is available at http://devauthority.com/blogs/jwooley/archive/2005/07/28/318.aspx.

Jim Woole
 
Back
Top