Results 1 to 8 of 8
  1. #1
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Check if another application is running (Access97)

    I have a situation where I have to export data using TCP. The data is sent to another application (autoreport) that listens on a specific port, and then a conversation takes place where each piece of data is sent and acknowledged. I have got all this to work.
    But it can't happen unless autoreport is already running.
    I can launch autoreport using the Shell command.
    <pre>retval = Shell("C:Program FilesSecur@TAutoReport.exe", vbNormalNoFocus) </pre>


    I would prefer to find a way of testing if autoreport is already running, and only try to start it if it is not running.

    Can this be done?
    Regards
    John



  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Check if another application is running (Access97)

    I believe it depends on the capabilities of autoreport - if it can report it is already running, then you should be able to do the test. On the other hand, this kind of application based on Access97 and whatever OS you are using sounds rather fragile to me. I would be much more comfortable doing the export to a file and then letting autoreport pick up the data at it's leisure.
    Wendell

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Check if another application is running (Acces

    Thanks
    I would also be more comfortable writing the stuff to a file, but the authors of autoreport have written it this way and I have to try to work with it.

    To my surprise, it does seem to work , although I am still at the testing stage.

    I will find out from the developers whether it is capable of reporting that it is already running.


    (Autoreport is a programme for electronic transmission of pathology reports. It encrypts the reports, and formats them to comply with an Australian standard HL7)
    Regards
    John



  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check if another application is running (Acces

    If you use a long instead of a boolean return value for IsOpen(), the value returned by the FindWindow call should be the hWnd of the specified application. That would be more useful than a simple boolean, wouldn't it?
    Charlotte

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check if another application is running (Acces

    Yes of course, but if you need the window handle, you might as well use the FindWindow function directly.

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Check if another application is running (Acces

    Thanks Hans

    That worked perfectly, once I changed :
    <pre>Public Sub IsOpen(strCaption As String) As Boolean
    IsOpen = FindWindow(vbNullString, strCaption)
    End If
    </pre>


    to

    <pre>Public Function IsOpen(strCaption As String) As Boolean
    IsOpen = FindWindow(vbNullString, strCaption)
    End Function
    </pre>

    Regards
    John



  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check if another application is running (Acces

    Good catch! You see it was just air code.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check if another application is running (Acces

    Note added later: IsOpen should be a function, not a sub - see John's remark later in this thread.

    You can use the Windows API function FindWindow to find out if a window with a specific title (caption) is open:

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Public Sub IsOpen(strCaption As String) As Boolean
    IsOpen = FindWindow(vbNullString, strCaption)
    End If

    Example use:

    If Not IsOpen("AutoReport") Then
    retval = Shell("C:Program FilesSecur@TAutoReport.exe", vbNormalNoFocus)
    End If

    You must use the exact caption of the window!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •