Home All Groups Group Topic Archive Search About

Single instance application

Author
21 Mar 2006 1:56 PM
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))
> 0 Then
    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.

Author
21 Mar 2006 2:58 PM
Chris
Marco wrote:
Show quoteHide quote
> 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))
>  > 0 Then
>     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
Author
21 Mar 2006 3:33 PM
Cor Ligthert [MVP]
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-343ac05a7617

I hope this helps,

Cor

Show quoteHide quote
"Marco" <nospampleasesyxxpk@hotmail.com> schreef in bericht
news:uNwZx8OTGHA.2088@TK2MSFTNGP14.phx.gbl...
>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))
> > 0 Then
>    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.
>
Author
21 Mar 2006 3:42 PM
Jim Wooley
> 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 Wooley
Author
21 Mar 2006 4:19 PM
Marco
That did it.  Thanks for the help everyone.


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:etM7ayPTGHA.5828@TK2MSFTNGP14.phx.gbl...
> 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-343ac05a7617
>
> I hope this helps,
>
> Cor
>
> "Marco" <nospampleasesyxxpk@hotmail.com> schreef in bericht
> news:uNwZx8OTGHA.2088@TK2MSFTNGP14.phx.gbl...
>>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))
>> > 0 Then
>>    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.
>>
>
>