Close a DOS program automatically

I've seen that this question has been asked by others but I can't seem to get any of the comments to those questions to work in my situation.  I know little about VB, but I really need to find a way to get my DOS program closed.

At night I run macros in my DOS database(Q&A version 4.0 DOS).  I do this simply by opening the program via windows task scheduler and with the correct command line suffix, the macros run and then the program closes - the macros end on the program's main menu and the keystroke to close the program from here is "X".  

My problem is that only one copy of the program can be open at once, so if someone forgets to close it at the end of the day (which tends to happen alot), the macros will not run - it will try but then abort and give a message that the program is already open.

What I need is a small exe file that I can open with my task scheduler just before my macros are set to run to check if the program is open and close it if it is.  The command line is C:\QA4\QA.COM.

As I mentioned I don't know VB very well, but I have worked with ACCESS a fair bit.  I have Visual Basic 6.0 from what I can tell, it looks similar to ACCESS in that I would need to create a form with some code attached to it, then compile it into a exe file??  Could someone confirm this process?  I'm pretty sure that with some help with the code and a general idea as to how to create a VB prject I will be on my way.

Thanks in advance

Max
LVL 1
MaxwellTurnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aeklundCommented:
1) Can you write your macros in a batch file, and after the last macro use the command "exit" to exit.

2) Or you can try to write a VB program to shell out the macros, e.g. Shell "C:\QA4\QA.COM"
0
vinnyd79Commented:
If you know the programs window caption you can try this:

' declarations
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_CLOSE = &H10


Private Sub Command1_Click()
Dim Handle As Long

' where "MS-DOS Prompt" is the window caption
Handle = FindWindow(vbNullString, "MS-DOS Prompt")
If Handle = 0 Then Exit Sub
SendMessage Handle, WM_CLOSE, 0&, 0&

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MaxwellTurnerAuthor Commented:
Aeklund - I have no problems closing the program after the macro's have run, the problem is making sure that it is closed boefore the macros run.

Vinnyd79 - I'm not sure what you mean by the window caption.  The program usually is run outside of windows.  I use Win98, but when I open the program, there is no window or caption.

Max
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

vinnyd79Commented:
Does the Program show up on the taskbar when it is open?If so,use the caption on the Taskbar.
0
MaxwellTurnerAuthor Commented:
Beatiful! It works . . well almost. I get a message box that opens up saying that windows cannot shut down this program automatically and it recommends that I use the program's exit command (which is keystroke "X" from the programs main menu).  There is however a choice YES or NO to shut the program down - when I choose YES, it closes.

Any way to handle this message box to select YES.

Another quick question:  I created a form in VB 6.0 and added a command button and attached the code you wrote to it.  I made it into an exe file, but I still have to click the button - how can execute the code when the form opens, and also have the form close after its done.

Max
0
MaxwellTurnerAuthor Commented:
Vinnyd79,

Well I still have the issue of the windows message popping up and saying it can't close the program automatically.  I have found a few others on EE that have had a similar problem, but couldn't find an solution.

Points to you for providing the code.  I'll ask a new question about the windows message an see if anyone can help.

Max
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.