Single instance application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco

    #1

    Single instance application

    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(Diagnost ics.Process.Get ProcessesByName (Diagnostics.Pr ocess.GetCurren tProcess.Proces sName))[color=blue]
    > 0 Then[/color]
    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.


  • Chris

    #2
    Re: Single instance application

    Marco wrote:[color=blue]
    > 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(Diagnost ics.Process.Get ProcessesByName (Diagnostics.Pr ocess.GetCurren tProcess.Proces sName))[color=green]
    > > 0 Then[/color]
    > 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.
    >
    >[/color]

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



    Chris

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Single instance application

      Marco,

      After long discussions probably the best.

      Have a look for it on our website.



      I hope this helps,

      Cor

      "Marco" <nospampleasesy xxpk@hotmail.co m> schreef in bericht
      news:uNwZx8OTGH A.2088@TK2MSFTN GP14.phx.gbl...[color=blue]
      >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(Diagnost ics.Process.Get ProcessesByName (Diagnostics.Pr ocess.GetCurren tProcess.Proces sName))[color=green]
      > > 0 Then[/color]
      > 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.
      >[/color]


      Comment

      • Jim Wooley

        #4
        Re: Single instance application

        > Marco,[color=blue]
        >
        > After long discussions probably the best.
        >
        > Have a look for it on our website.
        >
        > http://www.vb-tips.com/default.aspx?...1-9526-343ac05
        > a7617
        >
        > I hope this helps,
        >
        > Cor[/color]

        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/jwoole...07/28/318.aspx.

        Jim Wooley


        Comment

        • Marco

          #5
          Re: Single instance application

          That did it. Thanks for the help everyone.


          "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
          news:etM7ayPTGH A.5828@TK2MSFTN GP14.phx.gbl...[color=blue]
          > Marco,
          >
          > After long discussions probably the best.
          >
          > Have a look for it on our website.
          >
          > http://www.vb-tips.com/default.aspx?...6-343ac05a7617
          >
          > I hope this helps,
          >
          > Cor
          >
          > "Marco" <nospampleasesy xxpk@hotmail.co m> schreef in bericht
          > news:uNwZx8OTGH A.2088@TK2MSFTN GP14.phx.gbl...[color=green]
          >>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(Diagnost ics.Process.Get ProcessesByName (Diagnostics.Pr ocess.GetCurren tProcess.Proces sName))[color=darkred]
          >> > 0 Then[/color]
          >> 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.
          >>[/color]
          >
          >[/color]


          Comment

          Working...