Results 1 to 10 of 10

Thread: Watch for another app to end

  1. #1

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375

    Question Watch for another app to end

    I have been trying to figure this out for some time now...I want my first app (app A) to be able to detect when my other app(App B) has ended, or is no longer running for any reason. For instance, if app A exits or is ended, i want app B to be able to detect it. How would i do that?
    You just proved that sig advertisements work.

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Thumbs up

    One way i can see of doing that is:
    1. Make a timer on App A which uses an API to check if App B exists (is running)
    2. Same as above except App B checking App A this time.

    Thanx,
    Mikelo2k

  3. #3
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Wink

    Put this in the Declarations (module):

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

    ---------------------------------------

    1. First find out the class name of your APP (for notepad it's "Notepad")
    2. Repeat for the Other App.
    (If you want to knwo how to find out the class name jsut ask)
    3. Then you should put in a timer:
    If (FindWindow(ClassName,Caption\Title of the app) = 0 then
    .. 'Re-open your app or notify user ..
    End If

    Hope that is clear.

    Thanx,
    Mikelo2k

  4. #4

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Originally posted by Mikelo2k
    One way i can see of doing that is:
    1. Make a timer on App A which uses an API to check if App B exists (is running)
    2. Same as above except App B checking App A this time.

    Thanx,
    Mikelo2k
    I knew that...its just I have no idea which API would be best for something like this...
    You just proved that sig advertisements work.

  5. #5

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    *cough*
    You just proved that sig advertisements work.

  6. #6

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Anyone got any ideas?
    You just proved that sig advertisements work.

  7. #7
    DaoK
    Guest
    Add winsock ocx with the ip 127.0.0.1 and if he can connect then put a variable to a number and if he lost connection ( stop other program ) to an other number.

    Algo:
    1-
    ProgA connected
    MyVariable = 0
    ProgB not connected
    2-
    ProgA connected
    MyVariable = MyVariable +1 ' // (1)
    ProgB connected
    3-
    ProgA connected
    MyVariable = MyVariable +1 ' // ( 2 )
    ProgB not connected
    If MyVariable = 2 then not connected

    It's just an idea...using Winsock.

  8. #8

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Wouldnt the Winsock method conflict with other programs using 127.0.0.1 for any reason? I would rather not use Winsock...perhaps an API...anyone know if WaitForSingleObject can be used for that?
    You just proved that sig advertisements work.

  9. #9
    DaoK
    Guest
    well it will not be conflict if you are not using the same port. Maybe an API can do the job.

  10. #10
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    If you shell app A from app B then I guess you can.

    I would suggest putting the following code in an ax exe (to allow async execution) alternatively read up on the switches for the api calls which may allow you to execute the code asynchronously without using an ax exe.

    See here for detailed explanation: http://support.microsoft.com/support.../Q129/7/96.ASP
    From the above MSDN link:

    VB Code:
    1. Private Type STARTUPINFO
    2.       cb As Long
    3.       lpReserved As String
    4.       lpDesktop As String
    5.       lpTitle As String
    6.       dwX As Long
    7.       dwY As Long
    8.       dwXSize As Long
    9.       dwYSize As Long
    10.       dwXCountChars As Long
    11.       dwYCountChars As Long
    12.       dwFillAttribute As Long
    13.       dwFlags As Long
    14.       wShowWindow As Integer
    15.       cbReserved2 As Integer
    16.       lpReserved2 As Long
    17.       hStdInput As Long
    18.       hStdOutput As Long
    19.       hStdError As Long
    20.    End Type
    21.  
    22.    Private Type PROCESS_INFORMATION
    23.       hProcess As Long
    24.       hThread As Long
    25.       dwProcessID As Long
    26.       dwThreadID As Long
    27.    End Type
    28.  
    29.    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    30.       hHandle As Long, ByVal dwMilliseconds As Long) As Long
    31.  
    32.    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    33.       lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
    34.       lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    35.       ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    36.       ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
    37.       lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    38.       PROCESS_INFORMATION) As Long
    39.  
    40.    Private Declare Function CloseHandle Lib "kernel32" _
    41.       (ByVal hObject As Long) As Long
    42.  
    43.    Private Declare Function GetExitCodeProcess Lib "kernel32" _
    44.       (ByVal hProcess As Long, lpExitCode As Long) As Long
    45.  
    46.    Private Const NORMAL_PRIORITY_CLASS = &H20&
    47.    Private Const INFINITE = -1&
    48.  
    49.    Public Function ExecCmd(cmdline$)
    50.       Dim proc As PROCESS_INFORMATION
    51.       Dim start As STARTUPINFO
    52.  
    53.       ' Initialize the STARTUPINFO structure:
    54.       start.cb = Len(start)
    55.  
    56.       ' Start the shelled application:
    57.       ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
    58.          NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
    59.  
    60.       ' Wait for the shelled application to finish:
    61.          ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    62.          Call GetExitCodeProcess(proc.hProcess, ret&)
    63.          Call CloseHandle(proc.hThread)
    64.          Call CloseHandle(proc.hProcess)
    65.          ExecCmd = ret&
    66.    End Function
    67.  
    68.  
    69.  
    70.    Sub Form_Click()
    71.       Dim retval As Long
    72.       retval = ExecCmd("notepad.exe")
    73.       MsgBox "Process Finished, Exit Code " & retval
    74.    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width