?
Solved

Close a DOS program automatically

Posted on 2003-03-17
6
Medium Priority
?
198 Views
Last Modified: 2010-05-01
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
Comment
Question by:MaxwellTurner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:aeklund
ID: 8155738
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
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 1000 total points
ID: 8155860
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
 
LVL 1

Author Comment

by:MaxwellTurner
ID: 8156512
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Expert Comment

by:vinnyd79
ID: 8158469
Does the Program show up on the taskbar when it is open?If so,use the caption on the Taskbar.
0
 
LVL 1

Author Comment

by:MaxwellTurner
ID: 8168770
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
 
LVL 1

Author Comment

by:MaxwellTurner
ID: 8183143
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question