Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. only one instance of an exe?

only one instance of an exe?

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anju
    wrote on last edited by
    #1

    dear all, how can i restrict multiple instance of an exe? please....... :rose: anju

    T P R A 4 Replies Last reply
    0
    • A anju

      dear all, how can i restrict multiple instance of an exe? please....... :rose: anju

      T Offline
      T Offline
      Tim Deveaux
      wrote on last edited by
      #2

      Run it on a very small computer... ... or, check J.M.Newcomers (IIRC) exellent article (here on CP), or, search this forum for CreateMutex and you'll get some tips.

      B 1 Reply Last reply
      0
      • A anju

        dear all, how can i restrict multiple instance of an exe? please....... :rose: anju

        P Offline
        P Offline
        Paul M Watt
        wrote on last edited by
        #3

        Create a named mutex object when your app starts up. In your second app, if another mutex exists with that name, then exit the program. This is how VB implements their version of this.

        N 1 Reply Last reply
        0
        • T Tim Deveaux

          Run it on a very small computer... ... or, check J.M.Newcomers (IIRC) exellent article (here on CP), or, search this forum for CreateMutex and you'll get some tips.

          B Offline
          B Offline
          Brian Delahunty
          wrote on last edited by
          #4

          ROFLMAO :-O


          "Never tell people how to do things. Tell them what to do, and they will surprise you with their ingenuity." - General George S. Patton Jr.

          T 1 Reply Last reply
          0
          • P Paul M Watt

            Create a named mutex object when your app starts up. In your second app, if another mutex exists with that name, then exit the program. This is how VB implements their version of this.

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            kilowatt wrote: This is how VB implements their version of this. I didnt know that. How is it done from VB? Nish

            Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice

            D P 2 Replies Last reply
            0
            • B Brian Delahunty

              ROFLMAO :-O


              "Never tell people how to do things. Tell them what to do, and they will surprise you with their ingenuity." - General George S. Patton Jr.

              T Offline
              T Offline
              Tim Deveaux
              wrote on last edited by
              #6

              No - seriously - this Newcomer guy is good!

              1 Reply Last reply
              0
              • N Nish Nishant

                kilowatt wrote: This is how VB implements their version of this. I didnt know that. How is it done from VB? Nish

                Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice

                D Offline
                D Offline
                Daniel Lohmann
                wrote on last edited by
                #7

                kilowatt wrote: This is how VB implements their version of this. I didnt know that. How is it done from VB? Forget about it! Even if this is the "offical" way to do it, it has some bad limitations, especially in NTs multiuser/multidesktop environment. I strongly recommend to read the excellent article from Joseph which shows everything about this topic. Some ready to use C-Code can that takes account of this problems can be found here. -- Daniel Lohmann http://www.losoft.de

                P 1 Reply Last reply
                0
                • N Nish Nishant

                  kilowatt wrote: This is how VB implements their version of this. I didnt know that. How is it done from VB? Nish

                  Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice

                  P Offline
                  P Offline
                  Paul M Watt
                  wrote on last edited by
                  #8

                  You reference the app object and test the hPrevInstance variable. It will return true if there is an previous instance of the app, false if there is not.

                  If (App.PrevInstance) Then
                  MsgBox "Previous Instance Found"
                  Else
                  MsgBox "No Previous Instance"
                  End If

                  Basically this feature is implemented internally with the named mutex as I mentioned earlier in the thread.

                  1 Reply Last reply
                  0
                  • D Daniel Lohmann

                    kilowatt wrote: This is how VB implements their version of this. I didnt know that. How is it done from VB? Forget about it! Even if this is the "offical" way to do it, it has some bad limitations, especially in NTs multiuser/multidesktop environment. I strongly recommend to read the excellent article from Joseph which shows everything about this topic. Some ready to use C-Code can that takes account of this problems can be found here. -- Daniel Lohmann http://www.losoft.de

                    P Offline
                    P Offline
                    Paul M Watt
                    wrote on last edited by
                    #9

                    I think Nish was simply asking how you get access to the previous instance feature in VB. I don't think that just because VB implements it this way, that says this is the "official" way to do it.

                    1 Reply Last reply
                    0
                    • A anju

                      dear all, how can i restrict multiple instance of an exe? please....... :rose: anju

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #10

                      This is what I use. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

                      1 Reply Last reply
                      0
                      • A anju

                        dear all, how can i restrict multiple instance of an exe? please....... :rose: anju

                        A Offline
                        A Offline
                        anu
                        wrote on last edited by
                        #11

                        create a static instance for a type ex: static CMyClass *pInstance; // you need to initialize it... CMyClass *CMyClass::pinstance = NULL; add the following functions // constructing the object CMyClass *CMyClass::GetInstance() { if(pInstance== NULL) pInstance = new CMyClass; return pInstance; } // destructing the object void CSystemManager::DeleteInstance() { if( pInstance) delete pInstance; pInstance = NULL; } apart from constructor and destructor... Now... you can happily access the singleton thro GetInstance() function. call DeleteInstance() when you are done with that. -anu

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups