Programmatically shutting down a running program
Is there a way that I can shutdown a running application from a VB6 app? I would like to automate the shutdown and restart of the application at the same time each day. I know that I can use task scheduler to restart the application, but what about shutting it down? All help and ideas appreciated!
[298 byte] By [
rowlama1] at [2007-11-11 10:30:38]

# 2 Re: Programmatically shutting down a running program
Phil,
I appreciate your fast response. Unfortunately, when attempting to close the application in this manner, the application responds with a "Are You Sure" modal dialog that has a "Yes" and a "No" button. If I use the same methodology to close this dialog box, the application is unaffected, and keeps running. In order to shutdown the application cleanly, I need to be able to respond with a "Yes" message to this dialog. I cannot locate any documented constants to do this using the postmessage API of user32. Can this be done? The only way that the shutdown works is by using the constant "WM_QUIT" instead of "WM_CLOSE" in the postmessage function, but the application does not shutdown cleanly -- it appears to be ripped out of memory. Since this application is linked to a database, I need the shutdown to be clean. Any other suggestions? All are welcome and appreciated!
# 4 Re: Programmatically shutting down a running program
Haven't looked at Phil's links, but here is a suggestion ...
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
glHandle = FindWindowEx(0, 0, vbNullString, "Whatever is the 'Caption' of the window you wish to close")
ShowWindow glHandle, SW_SHOWMAXIMIZED
SendKeys "%{F4}{Enter}", True 'Close Application
gupex at 2007-11-11 17:25:35 >

# 5 Re: Programmatically shutting down a running program
Phil, gupex,
I'm a bit late replying to this post, but I wanted to say that I appreciate both of your responses. I did use the "SendKeys" command to respond to the dialog box, along with the API's listed in the support article that Phil referenced. It works quite well, and I wanted to at least come back and let you both know. I appreciate your input very much!
rowlama1