I found an example in this forum that led me to this example in the MS knowledge base (Article - 176391) and I tried to use it to close Express ClickYes app, but it doesn't work. Seem like the code freezes at line in red. If you manually close the app in the systray the code then resumes and recognizes that all instances have now been closed. It knows its open, but it can't close it. Thanks in advance.
Private Sub Command2_Click()
'Closes Windows Calculator
Dim hWindow As Long
Dim hThread As Long
Dim hProcess As Long
Dim lProcessId As Long
Dim lngResult As Long
Dim lngReturnValue As Long
'hWindow = FindWindow(vbNullString, "Click")
hWindow = FindWindow(vbNullString, "Express ClickYes 1.0.7")
hThread = GetWindowThreadProcessId(hWindow, lProcessId)
hProcess = OpenProcess(SYNCHRONIZE, 0&, lProcessId)
lngReturnValue = PostMessage(hWindow, WM_CLOSE, 0&, 0&)
lngResult = WaitForSingleObject(hProcess, INFINITE)
'Does the handle still exist?
DoEvents
'hWindow = FindWindow(vbNullString, "Click")
hWindow = FindWindow(vbNullString, "Express ClickYes 1.0.7")
If IsWindow(hWindow) = 1 Then
'The handle still exists. Use the TerminateProcess function
'to close all related processes to this handle. See the
'article for more information.
MsgBox "Handle still exists."
Else
'Handle does not exist.
MsgBox "All Program Instances Closed."
End If
End Sub
Private Sub Command2_Click()
'Closes Windows Calculator
Dim hWindow As Long
Dim hThread As Long
Dim hProcess As Long
Dim lProcessId As Long
Dim lngResult As Long
Dim lngReturnValue As Long
'hWindow = FindWindow(vbNullString, "Click")
hWindow = FindWindow(vbNullString, "Express ClickYes 1.0.7")
hThread = GetWindowThreadProcessId(hWindow, lProcessId)
hProcess = OpenProcess(SYNCHRONIZE, 0&, lProcessId)
lngReturnValue = PostMessage(hWindow, WM_CLOSE, 0&, 0&)
lngResult = WaitForSingleObject(hProcess, INFINITE)
'Does the handle still exist?
DoEvents
'hWindow = FindWindow(vbNullString, "Click")
hWindow = FindWindow(vbNullString, "Express ClickYes 1.0.7")
If IsWindow(hWindow) = 1 Then
'The handle still exists. Use the TerminateProcess function
'to close all related processes to this handle. See the
'article for more information.
MsgBox "Handle still exists."
Else
'Handle does not exist.
MsgBox "All Program Instances Closed."
End If
End Sub