Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing exe via FoxPro

Status
Not open for further replies.

ShortyII

Programmer
Sep 8, 2003
57
0
0
NL
Hello,

This is wath i want to do.
Check if a application is running if it does then close it.

I know how to check on running apps:
FindWindow is the title bar of the window
SET LIBRARY TO CFYPATH + "\exe\foxtools.fll" ADDITIVE
lGetwind = regfn("FindWindow","CC","I")
lWclass=0
lHandle=callfn(lGetwind,lWclass,lWindowTitle)
IF lHandle <> 0
ON KEY LABEL ESCAPE *
SET ESCAPE OFF
WAIT WINDOW &quot;THIS PROGRAM IS ALREADY RUNNING !&quot; NOWAIT
QUIT
ENDIF
SET LIBRARY TO


But how can i close the running app ?
The app isn't foxpro but a own written vb app.

Thanx
 
You may be able to use Windows Scripting Host or API calls to close the already running app, but I think you should rethink your strategy. If an app is already running, forcing it to close could cause problems with data corruption and so on.
The safest thing to do would be to let your app bring the other one to the foreground first, then terminate its own instance. Maybe something like:

WAIT WINDOW &quot;THIS PROGRAM IS ALREADY RUNNING !&quot; TIMEOUT 2
!/n Wscript ontop.vbs
QUIT


Here is the code for ontop.vbs:
set objontop = CreateObject(&quot;WScript.Shell&quot;)
objontop.AppActivate(&quot;WhateverTheAppIsNamed&quot;)

Of course, WSH needs to be installed, and it also needs to be version 2.0 or greater.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Thanx for the help dave
But the program i want to close is just a label that changes every minute. So there is no data issue.

Anyone else who knows??
 
Shorty,
Are you running under Windows 3.x? If you are running under a 32-bit OS (Win 9,x, NT/2000/XP), the problem is that many of the API calls aren't directly available through FOXTOOLS. You'll may need to use CALL32 - available at Even this isn't really reliable in all API calls or under all OS's.

Check to see if API SendMessage() with the &quot;close&quot; option works. (Close is where the 2nd parameter has a value of 16.)

Rick
 
Hi Rik,

The option you should be the one.
But all examples i can find on the internet are for VB and VFP when trying to use these i get the error that he dosn't now the function SendMessage but i tryed to use CALL32 but no succes. Maybe you can help me or do you have a code sample for fox2.6

Great thanx in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top