Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

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
0
MaxwellTurner
Asked:
MaxwellTurner
  • 3
  • 2
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now