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. Identifying a currently running application

Identifying a currently running application

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionlounge
9 Posts 4 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.
  • P Offline
    P Offline
    pix_programmer
    wrote on last edited by
    #1

    Hi! How Windows XP(in general any Windows OS) identifies the currently running VC++ application?

    P 1 Reply Last reply
    0
    • P pix_programmer

      Hi! How Windows XP(in general any Windows OS) identifies the currently running VC++ application?

      P Offline
      P Offline
      pandit84
      wrote on last edited by
      #2

      If you want to know the name of Currently running .exe . Use GetModuleFileName() See here http://msdn.microsoft.com/en-us/library/ms683197(v=vs.85).aspx

      P 1 Reply Last reply
      0
      • P pandit84

        If you want to know the name of Currently running .exe . Use GetModuleFileName() See here http://msdn.microsoft.com/en-us/library/ms683197(v=vs.85).aspx

        P Offline
        P Offline
        pix_programmer
        wrote on last edited by
        #3

        I've created a Single Instance application using the following code:

        if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
        {
        long dwError = ::GetLastError();
        if(dwError == ERROR_ALREADY_EXISTS)
        // MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB_OK);
        EndDialog(NULL,IDOK);
        }

        I've designed one project as a template and used it to build many applications. e.g I tried to run one application named "app2" while another application named "app1" is already running. But "app2" does not run. I don't want this. "app2" should not run if and only if "app2" is already running. Otherwise it has to run normal. How to do this?

        S A 2 Replies Last reply
        0
        • P pix_programmer

          I've created a Single Instance application using the following code:

          if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
          {
          long dwError = ::GetLastError();
          if(dwError == ERROR_ALREADY_EXISTS)
          // MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB_OK);
          EndDialog(NULL,IDOK);
          }

          I've designed one project as a template and used it to build many applications. e.g I tried to run one application named "app2" while another application named "app1" is already running. But "app2" does not run. I don't want this. "app2" should not run if and only if "app2" is already running. Otherwise it has to run normal. How to do this?

          S Offline
          S Offline
          ShilpiP
          wrote on last edited by
          #4

          Create a guid by using guidgen.exe and check this code ->[^]

          "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

          P 1 Reply Last reply
          0
          • S ShilpiP

            Create a guid by using guidgen.exe and check this code ->[^]

            "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

            P Offline
            P Offline
            pix_programmer
            wrote on last edited by
            #5

            I solved the problem patially by following the above link. Now my problem is: If I close one instance the other instance is also closed. How to fix this?

            S 1 Reply Last reply
            0
            • P pix_programmer

              I solved the problem patially by following the above link. Now my problem is: If I close one instance the other instance is also closed. How to fix this?

              S Offline
              S Offline
              ShilpiP
              wrote on last edited by
              #6

              pix_programmer wrote:

              If I close one instance the other instance is also closed. How to fix this?

              How it is possible ?? Are you using this code in InitInstance.

              if (g_SingleInstanceObj.IsAnotherInstanceRunning())
              return FALSE;

              If you are using this code in InitInstance than another instance is not getting created but the running instance is not getting closed. Please share your code.

              "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

              P 1 Reply Last reply
              0
              • S ShilpiP

                pix_programmer wrote:

                If I close one instance the other instance is also closed. How to fix this?

                How it is possible ?? Are you using this code in InitInstance.

                if (g_SingleInstanceObj.IsAnotherInstanceRunning())
                return FALSE;

                If you are using this code in InitInstance than another instance is not getting created but the running instance is not getting closed. Please share your code.

                "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

                P Offline
                P Offline
                pix_programmer
                wrote on last edited by
                #7

                I've not used the above code. I used the following code.

                if(NULL != ::CreateMutex(NULL, TRUE,\_T("{AFD2966D-9A83-4E3A-9C9E-CD81E96D819A}")))
                {
                	long dwError = ::GetLastError();
                	if(dwError == ERROR\_ALREADY\_EXISTS)
                		//	MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB\_OK);
                		EndDialog(NULL,IDOK);
                

                }

                By instance I do not mean same application instance. If I close app1, app2 is also closed. What to do?

                S 1 Reply Last reply
                0
                • P pix_programmer

                  I've not used the above code. I used the following code.

                  if(NULL != ::CreateMutex(NULL, TRUE,\_T("{AFD2966D-9A83-4E3A-9C9E-CD81E96D819A}")))
                  {
                  	long dwError = ::GetLastError();
                  	if(dwError == ERROR\_ALREADY\_EXISTS)
                  		//	MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB\_OK);
                  		EndDialog(NULL,IDOK);
                  

                  }

                  By instance I do not mean same application instance. If I close app1, app2 is also closed. What to do?

                  S Offline
                  S Offline
                  ShilpiP
                  wrote on last edited by
                  #8

                  pix_programmer wrote:

                  If I close app1, app2 is also closed. What to do?

                  What do you mean app1 and app2?? Are you talking about instance of same application?? If CreateMutex is fail than it returns NULL and you are checking that if it is not null than you are checking GetLastError.

                  if(NULL == ::CreateMutex(NULL, TRUE,_T("{AFD2966D-9A83-4E3A-9C9E-CD81E96D819A}")))
                  {
                  long dwError = ::GetLastError();
                  if(dwError == ERROR_ALREADY_EXISTS)
                  {
                  EndDialog(NULL,IDOK);
                  return FALSE;
                  }
                  }

                  "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."

                  1 Reply Last reply
                  0
                  • P pix_programmer

                    I've created a Single Instance application using the following code:

                    if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
                    {
                    long dwError = ::GetLastError();
                    if(dwError == ERROR_ALREADY_EXISTS)
                    // MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB_OK);
                    EndDialog(NULL,IDOK);
                    }

                    I've designed one project as a template and used it to build many applications. e.g I tried to run one application named "app2" while another application named "app1" is already running. But "app2" does not run. I don't want this. "app2" should not run if and only if "app2" is already running. Otherwise it has to run normal. How to do this?

                    A Offline
                    A Offline
                    Abhi Lahare
                    wrote on last edited by
                    #9

                    If I read your correctly, the name of mutex should be unique ,pass some unique string while creating first instance of app1,app2 and so on. the reason you are getting problem you are using the same mutex name for all the application. HTH

                    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