Results 1 to 5 of 5

Thread: How to detect a running application

  1. #1
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default How to detect a running application

    Hi,
    I have a requirement where I need to start a separate background application (non gui)from one of my demo application. But it can so happen that the background application is already running.
    Is there any API or class thorugh which I can determine whether the background application is already running and need not start it again. I am trying to use QProcess to start the background application from my demo application.

    Thanks in advance.
    Yogesh

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect a running application

    Is it a 3rd party application (I mean the background app) or can you modify it? if so, you can use QSharedMemory for example.

  3. The following user says thank you to wysota for this useful post:

    yogesh (20th February 2009)

  4. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to detect a running application

    for windows specific check, here is how u do it:

    Qt Code:
    1. bool URCLASS::alreadyExists(wchar_t * appFileName)
    2. {
    3.  
    4. /// Create mutex named for the current exe and check for its existence
    5. bool bResult = false;
    6.  
    7. // Don't separate these next two statements; GetLastError()
    8. // must be the first call after the CreateMutex() call
    9. hMutex = ::CreateMutex(NULL, TRUE, appFileName);
    10. DWORD dwLastError = ::GetLastError();
    11.  
    12. // If the mutex already exists, return true to indicate that this exe
    13. // is already running.
    14. if (dwLastError == ERROR_ALREADY_EXISTS)
    15. {
    16. bResult = true;
    17. }
    18.  
    19. return bResult;
    20. }
    To copy to clipboard, switch view to plain text mode 

    is that what u need?

  5. #4
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to detect a running application

    Hi,
    The background application is a server (that is again my own application )which can be accessed by any number of client applications running on the system. I want the mechanism to be generic so that I can use it across platform. can you please specify how to use QSharedMemory to get the desired result ?

    Thanks in advance.
    Regards,
    Yogesh

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect a running application

    In general in a fashion similar to this: [wiki]SingleApplication[/wiki].

    The minimal possible implementation would be to create a shared memory block in the server and try to attach to it from the client. If the block already exists it means the server is running.

    Another approach (without shared memory) is to open a local socket from within the server and connect to it from the client. If the connection is successful, it means the server is running.

Similar Threads

  1. How to invoke a running application
    By srikanthch in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2008, 15:42
  2. How to detect a QProcess is started
    By cooler123 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 10:45
  3. Replies: 5
    Last Post: 9th June 2008, 11:21
  4. Replies: 10
    Last Post: 10th March 2008, 12:28
  5. Replies: 10
    Last Post: 11th June 2007, 09:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.