Terminate an Executable Application in Visual Foxpro 9.0 at Run-time by Force

To terminate an executable application in Visual FoxPro 9.0 at run-time, use the RUN and Taskkill command. RUN is a Visual FoxPro command that allows you to execute DOS commands, Taskkill, on the other hand, is DOS command that allows you to terminate an exe applications and processes , similar to using the task manager. For details on using the taskkill command, follow these steps:

1. Click Start>Run>Type CMD> then press enter.

2. In the command prompt, type TASKKILL/?.

Using Run and Taskkill to terminate an executable application at run-time is essential especially if you have hidden the Visual FoxPro 9 IDE using the _SCREEN.VISIBLE command and your form just freezes when you click the Exit button, even though you have attached a THISFORM.RELEASE or whatever code to it. To see RUN and TASKKILL in action, follow these steps:


1. Click Start>All Programs>Microsoft Visual FoxPro 9.0.

2. Close the Task Pane Manager window.


3. Let’s make a form by typing CREA FORM in the command window and pressing enter.

Note: If the command window is hidden, just press CTRL + F2 to show it.

4. Add two buttons to your form, Refer to the following screenshot for control names and values:




5. Double-click the Terminate Ms-Word button, enter the following codes:

private anyvariable
anyvariable=MESSAGEBOX(“Are you sure you want to terminate Ms-Word?”,4+32)
if anyvariable=6
RUN "Taskkill /f /im winword.exe”
ENDIF


Your code window should now look like this:



6. Double-click the Terminate Visual FoxPro button, enter the following codes:
private anyvariable
anyvariable=MESSAGEBOX(“Are you sure you want to terminate Ms-Word?”,4+32)
if anyvariable=6
RUN "Taskkill /f /im VFP9.exe”
ENDIF
Your code window should now look like this:


7. Press CTRL + F3 to test your application.

8. Before Clicking the Terminate Ms-Word button, ensure that Ms-word is activated.

9. Try clicking the Terminate Visual FoxPro button and see what happens. And that’s all :)