|
-
Dec 2nd, 2001, 02:18 PM
#1
Thread Starter
Frenzied Member
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.
-
Dec 2nd, 2001, 02:35 PM
#2
Addicted Member
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
-
Dec 2nd, 2001, 02:43 PM
#3
Addicted Member
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
-
Dec 2nd, 2001, 02:44 PM
#4
Thread Starter
Frenzied Member
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.
-
Dec 2nd, 2001, 03:50 PM
#5
Thread Starter
Frenzied Member
You just proved that sig advertisements work.
-
Dec 2nd, 2001, 06:57 PM
#6
Thread Starter
Frenzied Member
You just proved that sig advertisements work.
-
Dec 2nd, 2001, 07:02 PM
#7
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.
-
Dec 2nd, 2001, 07:06 PM
#8
Thread Starter
Frenzied Member
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.
-
Dec 2nd, 2001, 07:07 PM
#9
well it will not be conflict if you are not using the same port. Maybe an API can do the job.
-
Dec 2nd, 2001, 09:46 PM
#10
Registered User
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:
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
Sub Form_Click()
Dim retval As Long
retval = ExecCmd("notepad.exe")
MsgBox "Process Finished, Exit Code " & retval
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|