Shutting down an external program 
Author Message
 Shutting down an external program

Does anyone know how to:

1. Detect whether or not an external program is running?
2. If it is running, shut it down?

The specific program I am writing (in Visual Foxpro 6, with Service Pack 3)
has a button to access some scanned image files.  It uses the RUN command to
open the Kodak imaging program (that comes as part of Windows 95/98) which
in turn loads the necessary image file.  I don't want users forgetting to
shut down Kodak imaging, and therefore opening up another instance of the
imaging program when they click on the "access scanned image" button in my
program.  So, before running Kodak imaging, I need to check whether or not
it is already open, and if it is, to shut it down first.

If I need to access the Windows API to do this then please let me know, but
bear in mind that I don't know any C or C++ and have never accessed the
Windows API before - please be gentle.

Thanks for your help.

Gia



Sun, 23 Jun 2002 03:00:00 GMT  
 Shutting down an external program
[ Courtesy cc'ed through e-mail to the quoted author ]

Quote:
>Does anyone know how to:

>1. Detect whether or not an external program is running?
>2. If it is running, shut it down?

>The specific program I am writing (in Visual Foxpro 6, with Service Pack 3)
>has a button to access some scanned image files.  It uses the RUN command to
>open the Kodak imaging program (that comes as part of Windows 95/98) which
>in turn loads the necessary image file.  I don't want users forgetting to
>shut down Kodak imaging, and therefore opening up another instance of the
>imaging program when they click on the "access scanned image" button in my
>program.  So, before running Kodak imaging, I need to check whether or not
>it is already open, and if it is, to shut it down first.

Why don't you use DDE?  I believe it was designed specifically for that.

[ When replying, remove *'s from address ]
Alexandre Pechtchanski, Systems Manager, RUH, NY



Sun, 23 Jun 2002 03:00:00 GMT  
 Shutting down an external program
Following code assumes you know the exact caption of the window:

procedure KillWindow
lpara WindowTitle
#define WM_CLOSE 0x0010
declare integer FindWindow in User32 string classname, string windowname
declare integer SendMessage in User32 integer windowhandle, integer
message, integer wparam, integer lparam
local x
x = findwindow(0,m.WindowTitle)
if x=0
        MessageBox('Window not found: '+m.WindowTitle)
else
        sendmessage(x, WM_CLOSE, 0, 0)
endif
return

test code:

run /n notepad
do KillWindow with 'Untitled - Notepad'

This example works on NT at least, should work also on Win95.
Rgds,
Paavo.

Quote:

> Does anyone know how to:

> 1. Detect whether or not an external program is running?
> 2. If it is running, shut it down?

> The specific program I am writing (in Visual Foxpro 6, with Service Pack 3)
> has a button to access some scanned image files.  It uses the RUN command to
> open the Kodak imaging program (that comes as part of Windows 95/98) which
> in turn loads the necessary image file.  I don't want users forgetting to
> shut down Kodak imaging, and therefore opening up another instance of the
> imaging program when they click on the "access scanned image" button in my
> program.  So, before running Kodak imaging, I need to check whether or not
> it is already open, and if it is, to shut it down first.

> If I need to access the Windows API to do this then please let me know, but
> bear in mind that I don't know any C or C++ and have never accessed the
> Windows API before - please be gentle.

> Thanks for your help.

> Gia



Mon, 24 Jun 2002 03:00:00 GMT  
 Shutting down an external program

Quote:
> Does anyone know how to:

> 1. Detect whether or not an external program is running?
> 2. If it is running, shut it down?

> The specific program I am writing (in Visual Foxpro 6, with Service Pack
3)
> has a button to access some scanned image files.  It uses the RUN command
to
> open the Kodak imaging program (that comes as part of Windows 95/98) which
> in turn loads the necessary image file.  I don't want users forgetting to
> shut down Kodak imaging, and therefore opening up another instance of the
> imaging program when they click on the "access scanned image" button in my
> program.  So, before running Kodak imaging, I need to check whether or not
> it is already open, and if it is, to shut it down first.

> If I need to access the Windows API to do this then please let me know,
but
> bear in mind that I don't know any C or C++ and have never accessed the
> Windows API before - please be gentle.

> Thanks for your help.

> Gia

Why not placing the Kodak ActiveX Image Edit control on a form? Instead of
calling en external program, show the form, set the control's property
.image to the complete path with image file name and then call .display().
As soon as the user ist finished with viewing, just release the form.
ST


Mon, 24 Jun 2002 03:00:00 GMT  
 Shutting down an external program
Paavo
Do you have a routine to create list of running tasks, like the one
ctrl.alt-del presents?
-Anders

| Following code assumes you know the exact caption of the window:
|
| procedure KillWindow
| lpara WindowTitle
| #define WM_CLOSE 0x0010
| declare integer FindWindow in User32 string classname, string windowname
| declare integer SendMessage in User32 integer windowhandle, integer
| message, integer wparam, integer lparam
| local x
| x = findwindow(0,m.WindowTitle)
| if x=0
| MessageBox('Window not found: '+m.WindowTitle)
| else
| sendmessage(x, WM_CLOSE, 0, 0)
| endif
| return
|
|
| test code:
|
| run /n notepad
| do KillWindow with 'Untitled - Notepad'
|
| This example works on NT at least, should work also on Win95.
| Rgds,
| Paavo.
|
|
| >
| > Does anyone know how to:
| >
| > 1. Detect whether or not an external program is running?
| > 2. If it is running, shut it down?
| >
| > The specific program I am writing (in Visual Foxpro 6, with Service Pack
3)
| > has a button to access some scanned image files.  It uses the RUN
command to
| > open the Kodak imaging program (that comes as part of Windows 95/98)
which
| > in turn loads the necessary image file.  I don't want users forgetting
to
| > shut down Kodak imaging, and therefore opening up another instance of
the
| > imaging program when they click on the "access scanned image" button in
my
| > program.  So, before running Kodak imaging, I need to check whether or
not
| > it is already open, and if it is, to shut it down first.
| >
| > If I need to access the Windows API to do this then please let me know,
but
| > bear in mind that I don't know any C or C++ and have never accessed the
| > Windows API before - please be gentle.
| >
| > Thanks for your help.
| >
| > Gia



Mon, 24 Jun 2002 03:00:00 GMT  
 Shutting down an external program
I don't have such routine. However, I looked into MSDN library for
appropriate SDK functions and found there several Enum... procedures. It
depends on what exactly one wants to get. In Windows one has processes,
threads and nonchild windows, to begin with. There are separate SDK
calls for enumerating each of these categories. Typically these SDK
procedures need a pointer of a callback function which is impossible to
pass directly from FoxPro, so one has to write a small C wrapper and put
it into a separate DLL. There exist also standard Unix-like command-line
utilities for WinNT, like ps, kill and others. It might be simpler to
execute those and parse the output, but then one gets flickering dos
windows on the screen and one never knows if ps and text parsing
programs are installed on the system or not... Sorry, I started with
FoxPro question but turned to think how much simpler it is to do such
things on Unix, I'm sure that an average FoxPro developer was able to
use ps/grep/awk without much trouble, comparing to the C callback
function defining and DLL building which is needed for Windows platform;
but then again I'm pretty sure there are nice VB solutions for such
tasks I don't know anything about...

Paavo

Quote:

> Paavo
> Do you have a routine to create list of running tasks, like the one
> ctrl.alt-del presents?
> -Anders


> | Following code assumes you know the exact caption of the window:
> |
> | procedure KillWindow
> | lpara WindowTitle
> | #define WM_CLOSE 0x0010
> | declare integer FindWindow in User32 string classname, string windowname
> | declare integer SendMessage in User32 integer windowhandle, integer
> | message, integer wparam, integer lparam
> | local x
> | x = findwindow(0,m.WindowTitle)
> | if x=0
> | MessageBox('Window not found: '+m.WindowTitle)
> | else
> | sendmessage(x, WM_CLOSE, 0, 0)
> | endif
> | return
> |
> |
> | test code:
> |
> | run /n notepad
> | do KillWindow with 'Untitled - Notepad'
> |
> | This example works on NT at least, should work also on Win95.
> | Rgds,
> | Paavo.
> |
> |

> | >
> | > Does anyone know how to:
> | >
> | > 1. Detect whether or not an external program is running?
> | > 2. If it is running, shut it down?
> | >
> | > The specific program I am writing (in Visual Foxpro 6, with Service Pack
> 3)
> | > has a button to access some scanned image files.  It uses the RUN
> command to
> | > open the Kodak imaging program (that comes as part of Windows 95/98)
> which
> | > in turn loads the necessary image file.  I don't want users forgetting
> to
> | > shut down Kodak imaging, and therefore opening up another instance of
> the
> | > imaging program when they click on the "access scanned image" button in
> my
> | > program.  So, before running Kodak imaging, I need to check whether or
> not
> | > it is already open, and if it is, to shut it down first.
> | >
> | > If I need to access the Windows API to do this then please let me know,
> but
> | > bear in mind that I don't know any C or C++ and have never accessed the
> | > Windows API before - please be gentle.
> | >
> | > Thanks for your help.
> | >
> | > Gia



Fri, 28 Jun 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. shut down from vfp

2. Shut down application at midnight

3. Fatal Exception Error and Shut Down

4. Closing application when Windows shut down

5. Shut down Windows 95 programmatically

6. VFP5 shuts down machine

7. Shutting down Windows from foxpro

8. Shut Down Windows

9. Shutting down Win95 from VFP 3.0b

10. Executable keeps shutting down

11. Shut down application if no activity

12. Can you shut down an ole server

 

 
Powered by phpBB® Forum Software