How to kill a Windows App of which I have only the exe binary program?

I have a 3rd party Windows App exe. I start the App within my Main App
using CreateProcess.
However I am using TerminateProcess and it doesn't seem to properly
kill the Windows App.

I have read that TerminateProcess is not so clean and that other
Windows Programmers use the
WM_CLOSE message. How can I use WM_CLOSE if I don't control the guts of
this 3rd party Windows App exe ?

This Windows App exe uses sockets to network to another platform and I
have no control over any
objects it may create such as files, mutexes, etc.

I am using Windows XP and VC++.Net any help is appreciated.

Thanks

0
12/28/2006 7:23:53 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
362 Views

Similar Articles

[PageSpeed] 9

> I have read that TerminateProcess is not so clean and that other
> Windows Programmers use the
> WM_CLOSE message. How can I use WM_CLOSE if I don't control the guts of
> this 3rd party Windows App exe ?

You dont have to contol the window. You can get the window
handle(FindWindow) and then use PostMessage(WM_CLOSE,...).

---
Ajay

0
ajaykalra (6842)
12/28/2006 7:26:18 PM
placidite1@yahoo.com wrote:
> I have a 3rd party Windows App exe. I start the App within my Main App
> using CreateProcess.
> However I am using TerminateProcess and it doesn't seem to properly
> kill the Windows App.
> 
> I have read that TerminateProcess is not so clean and that other
> Windows Programmers use the
> WM_CLOSE message. How can I use WM_CLOSE if I don't control the guts of
> this 3rd party Windows App exe ?

Can you close the app by clicking on the close button (top right 
corner)?  If so, using WM_CLOSE will work.  WM_CLOSE is simply the 
message sent when the close button is clicked by a user.  Your program 
can simulate that same action.

Use FindWindow to get the app's main window, then PostMessage WM_CLOSE 
to the main window.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
12/28/2006 7:57:43 PM
Scott McPhillips [MVP] wrote:
> placidite1@yahoo.com wrote:
> > I have a 3rd party Windows App exe. I start the App within my Main App
> > using CreateProcess.
> > However I am using TerminateProcess and it doesn't seem to properly
> > kill the Windows App.
> >
> > I have read that TerminateProcess is not so clean and that other
> > Windows Programmers use the
> > WM_CLOSE message. How can I use WM_CLOSE if I don't control the guts of
> > this 3rd party Windows App exe ?
>
> Can you close the app by clicking on the close button (top right
> corner)?  If so, using WM_CLOSE will work.  WM_CLOSE is simply the
> message sent when the close button is clicked by a user.  Your program
> can simulate that same action.
>
> Use FindWindow to get the app's main window, then PostMessage WM_CLOSE
> to the main window.
> 
> -- 
> Scott McPhillips [VC++ MVP]

0
12/29/2006 12:17:02 AM
Scott McPhillips [MVP] wrote:
> placidite1@yahoo.com wrote:
> > I have a 3rd party Windows App exe. I start the App within my Main App
> > using CreateProcess.
> > However I am using TerminateProcess and it doesn't seem to properly
> > kill the Windows App.
> >
> > I have read that TerminateProcess is not so clean and that other
> > Windows Programmers use the
> > WM_CLOSE message. How can I use WM_CLOSE if I don't control the guts of
> > this 3rd party Windows App exe ?
>
> Can you close the app by clicking on the close button (top right
> corner)?  If so, using WM_CLOSE will work.  WM_CLOSE is simply the
> message sent when the close button is clicked by a user.  Your program
> can simulate that same action.
>
> Use FindWindow to get the app's main window, then PostMessage WM_CLOSE
> to the main window.
>
> --
> Scott McPhillips [VC++ MVP]

What happens when I have 3 different Main apps calling one instance of
the Sub Window exe programs ? When I use CreateProcess and
TerminateProcess all main Apps know exactly when to kill each similar
Sub Window Program. FindWindow works only by program name, what to do
to control the Sub Window exe programs separately ?

Thanks to all for the help...

0
12/29/2006 12:20:41 AM
FindWindow will find *an* instance of an application, providing the caption strings match
(always a risky proposition, particularly for a maximized MDI app), it will not
necessarily find *the* instance of an application.  I consider it a profoundly unreliable
mechanism for terminating an application.

What I do is EnumWindows, and look for a window whose owning process is the same process
ID I got when I launched the process; that way, I know I have the right one.

If it is a window-based application, you can PostMessage(WM_CLOSE) to it.  If it is
console app (such as a compiler or similar console app) you can GenerateConsoleCtrlEvent,
which requires a special flag in CreateProcess to get an appropriate handle.
					joe

On Thu, 28 Dec 2006 14:57:43 -0500, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
wrote:

>placidite1@yahoo.com wrote:
>> I have a 3rd party Windows App exe. I start the App within my Main App
>> using CreateProcess.
>> However I am using TerminateProcess and it doesn't seem to properly
>> kill the Windows App.
>> 
>> I have read that TerminateProcess is not so clean and that other
>> Windows Programmers use the
>> WM_CLOSE message. How can I use WM_CLOSE if I don't control the guts of
>> this 3rd party Windows App exe ?
>
>Can you close the app by clicking on the close button (top right 
>corner)?  If so, using WM_CLOSE will work.  WM_CLOSE is simply the 
>message sent when the close button is clicked by a user.  Your program 
>can simulate that same action.
>
>Use FindWindow to get the app's main window, then PostMessage WM_CLOSE 
>to the main window.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
1/1/2007 10:02:03 PM
Reply:

Similar Artilces:

Windows 7 problem
When I use the mouse to press a button on my form, if I don't quickly move the mouse the button is automatically pressed again. How do I fix this? Thank you. If this is a command button, you could set its AutoRepeat property to No. In form design view, right-click the button and choose Properties. AutoRepeat is on the Other tab of the properties box. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "KRCMD" <KRCMD@discussions.micr...

Kill Excel silently
Hi, I batch file that queries a database and creates a flat file. I want to start Excel, make graph of the data and save it as an htm file. I then want to get out of Excel. I want to do this automatically twice daily (eg at midnight). I use Scheduled tasks and a macro to start Excel and create the graph But Excel won't quit so I've set the ask Scheduler to stop Excel afte 1 minute. Here's the problem ... I get a message saying that Excel has terminate unexpectedly and would I like to send an Error Report to Microsoft?! I cannot turn this message off no matter what Service I st...

Windows update doesnt start
Every time I click on "check for updates" it does not start at all. It says "windows cannot currently check for updates because the service is not running. You may need to restart your computer." I restart my computer and same thing happens again and again. Endrit wrote: > Every time I click on "check for updates" it does not start at all. > It says "windows cannot currently check for updates because the > service is not running. You may need to restart your computer." > I restart my computer and same thing happens again and again....

Communication between Client Application and Windows Service
Hi, I have a windows service running different threads (and progress events) which are taking some time. What is the best way for a client apllication to communicate with the service for asking its state (eg. progress of the tasks, taskcount, cancel tasks) ? Is there an easy way to do this? Sockets? Named pipes? And is there an example? Thank you Stefan Stefan Uhlemann wrote: > Hi, > > I have a windows service running different threads (and progress events) > which are taking some time. > What is the best way for a client apllication to communica...

Windows keeps creating new profiles
Hi, About 4 months ago, I set up three email profiles on my computer. Over the last month, I notice that new profiles (called "pstloadtmpXXX" where XXX is a three digit number) continue to build up. Right now, I have 90 email profiles that have the pstloadtmpXXX name. Does anyone know why this is happening and how I can stop it from continuing? It goes without saying that it takes a long time to delete 90 profiles individually so if anyone has any ideas about how to delete these profiles all at once, that would be terrific. Thanks Which email client (Outlook, OExpress...

Windows live mail
I updated my PC to Windows 7 with Windows Live Mail. Some of my emails in my Inbox shows up for about 5 secs. and then they disappear completely. They are not in any other folders: junk, deleted, trash, etc.. I did a search, but could not find them. Please help me. "Lost & Found" <LostFound@discussions.microsoft.com> wrote in message news:7E6C4803-D273-4D95-8994-7A417E117ED4@microsoft.com... > I updated my PC to Windows 7 with Windows Live Mail. Some of my emails in > my > Inbox shows up for about 5 secs. and then they disappear completely. They &g...

Sales Configurator
Hello, We are a manufacturing company using the Sales Configurator and Modifier. Whenever our users select an option in the Sales Configurator window, the selected line scrolls up to become the topmost line in the scroll-box. Also, the bullet indicating selection does not consistantly disappear when selections are changed. Has anyone come up with solutions for this disasterous behavior? ...

Windows 2000 to Windows 2003 upgrade Exchange Error
Hello. I am running a Windows 2000 Advanced Server SP4 system with Newly upgraded Exchange 2003 Enterprise with SP1. When I run the comptabily check for upgrading to Windows 2003 Enterprise I get the following error: Exchange Server 2003 Microsoft -------------------------------------------------------------------------------- Issue Description: Exchange Server 2003 has a known compatibility issue with this version of Windows. For more information, refer to http://go.microsoft.com/fwlink/?LinkId=37488. Contact Information: Microsoft Web site: http://www.microsoft.com Telephone: ...

Will a c# program run on any PC?
Hello, I am new to C# and think that it is a very interesting tool. But there is one question I couldn't find an answer til now: Any C# program needs a .NET framework to run to translate the intermediate language to the systems machine language. But will this framework be available everywhere? Is it generaly on any Windows-PC? And how about Linux-PCs? How large is the dependency of a C# program from the version of the framework? Say I develop for framework A, will it run on framework B (B younger than A)? And vice versa? Can there be several framework versions installed o...

How do I crate a web query, but of a windows file directory
Hi, I have an interesting problem which I have been trying to solve. I've got a windows explorer directory full of word files which go back 3 years. Their file names are all well formatted and can be imported into excel as text. I then use excel to sort the files from the names into invoice numbers, customer names, and billing date (all a part of the word file name). I also use excel to hyperlink back to the original file on the hard drive. Now I have a tool which anyone can use to retrieve a file. Problem: It's easy to add a batch of file names with hyperlinks to excel...

Outlook and dial up window
When I open Outlook 2000 in XP a dial up window is also sometimes displayed. This appears to be quite random. Where is the control switch located/ ...

help me please! windows media center problem(s)! (does same on 360
windows media center is gathering all my system sounds along with my songs into the library and when i play 360 it is so annoying because sometimes i can have 5 different system sounds in a row between songs so i have to keep the remote handy. any solutions? deleting them from windows library would help when on computer but i figure it would be gathered again when on the 360 streaming from the computer. thanks in advance rami5079@gmail.com or the forum if its too much of a inconvenience. What version of WMP and Windows? Make sure that WMP's list of monitored folder...

Windows Update uninstall problem
I hope I posted this in the right place. I tried to uninstall an update using a C++ application I made. I use the Windows Update Agent API create an IUpdateSession then an IUpdateInstaller I set the update collection for the installer and then use the IUpdateInstaller->Uninstall method but I get the 0x80240028 error message. I understand that this means an uninstall can be started only by WSUS but is there any way I to send a command to the WSUS to uninstall the update or to "associate" my application with the WSUS server? Thank you! I observed that the IUpdateSess...

How do you add/remove Windows 7 components?
How do you add/remove Windows 7 components, like games media centre, etc. "computerkiller" <computerkiller@discussions.microsoft.com> wrote in message news:B005B581-11F2-4F8D-BDF4-A6B27EAB287E@microsoft.com... > How do you add/remove Windows 7 components, like games media centre, etc. As your question has nothing to do with the .NET Framework (the topic supported in this discussion group, please refer to the links below for the Windows 7 support forums: http://social.answers.microsoft.com/Forums/en-US/category/windows7 http://social.technet.microsoft.com/...

Windows XP Desktop Classic style vs XP style Advance Appearances
I have my XP desktop as Classic style for one reason (see below) although I like the XP style better. I'm able with the Advance Appearance to show "Selected Items" with a Item: color of yellow and a font color of black / bold (as though I'm highlighting something. Do you know if it's possible to have the same appearance for selected items in the XP style? Thanks (B^>)-]=[ Have you tried right-click on the desktop, Properties and then go to Appearance tab to see if the Color Scheme is what you want. hth WSR wrote: > > I have ...

adding fields to windows written in .NET
In the past I was able to use Modifier or VBA to enhance and change screens in Dynamics GP. This was the case even for alternate or new screens added by third party products. I have noticed I am unable to do this for third party products converted to .NET for GP10. I am noticing more products are being converted to .NET I have also noticed I can't use extender for thsese screens. My questions are: 1. Can I still use modifier and VBA? 2. If not, how do I add additional fields/VBA? 3. If the developing ISV is the only one that can add fields/make changes what does this mean fo...

Windows XP upgrade
I just upgraded to XP and there was no warning or info that I would loose my address book and identity. I do think I have a back-up, but I wondered if it was backed up during the installation and I just have to import it. Aem, this newsgroup is for support of Outlook 97/98/2000/2002/2003 from the Office suite of products. Outlook Express is actually a separate program despite the similar name. For help with your OE questions, try an OE newsgroup such as microsoft.public.windows.inetexplorer.ie6_outlookexpress (for OE 6), or an OE help website such as http://insideOE.tomsterdam.com. If...

Darn Programming
I am trying to finish writing some simple program. My problem is that when I try and change the arguement from SELECTION CHANGE to CHANGE, it doesn't work. Can someone help? Private Sub Worksheet_Change(ByVal Target As Range) If Worksheets("Sheet3").Range("B3").Value = 2 Then Worksheets("Sheet1").Range("F3") = Worksheets("Sheet3").Range("F4").Value End Sub My second problem is that I would like my data rather than appearing in a cell, appear in a TEXT BOX. What do I do? Bull, Selection change gets fired when you click a...

multiple windows creation without
Hi, Does anybody know how to create multiple windows without having a Winproc for each of them? My coworker and me are thinking of creating a debugwindow class(to display various algorithm related waveform/images), so that the user can create one or a few of such objects to show some intermidate results at their own choice. I knew normally every window has a winproc defined. Is it possible to create multiple windows without writing each one a winproc? Which will be the my way to solve my problems? >Does anybody know how to create multiple windows without having a Winproc >for...

Windows XP SP3 and GP 10
We purchased 3 new computers that came with WXP SP3. I installed GP 10 SP3 and all was fine until I attempted to print purchase orders. I would go to Transactions->Purchase->Print Purchase Order Documents. I attempted to print 5 PO's and then after clicking print, the computer just sits there for about 2 minutes and then it finally printed. I then went to a WXP SP2 computer and attempted to print the same 5 PO's. They printed instantly. After trying everything under the sun, I went into the ODBC Adminstrator and changed the DSN to use SQL Server Client instead of SQ...

kill
wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kill you right now wo will kil...

creating a csv spreadsheet and formatting it via another program
I have a set of Linux korn shell and perl scripts (don't worry if you don't know what those are) that create a csv file that is automatically emailed from a Linux server to end users. I want to apply some simple formatting to the spreadsheet such as bold, column widths, number precession, right or left alignment, and word wrap. I guess that I could create a macro to do the formatting, but is there some way to have the macro applied automatically to the csv file without the end user doing anything? Is there some other way to do this that I am missing? A .csv file is just tex...

Window 2003
Can CRM be installed on a Windows 2003 environment. I currently have a 2003 DC and 2003 CRM server but CRM fails at the end of installation. CRM is not supported yet on server 2003 but it is coming. I believe other people have had success with crm on server 2003 so scan this newsgoup for messages relating to this area. "sal" <sal.raieta@aecio.com> wrote in message news:00cd01c35535$35dc17f0$a501280a@phx.gbl... > Can CRM be installed on a Windows 2003 environment. I > currently have a 2003 DC and 2003 CRM server but CRM > fails at the end of installation. Insta...

How to disable Contract Template window?
Hi All, Can we disable the pop up window to select Contract template, which comes up while creating a new contract? That means, whenever we crate a new contract, it always opens a pop up window to select contract template, can we disable that window not to pop up and takes a standard value for contract template? Any suggestions. Thanks in Advance. Ashwani Not in a supported manner. You could probably edit the underlying ASPX page though to remove the call. However, no telling what this might impact. Matt Parks MVP - Microsoft CRM ---------------------------------------- -----------...

Security for the PO in the PO Preview Window
Hello: I know that, in the Security window, there is the "Document Access" Type that prevents a user from having access to POs and sales orders and so forth. But, apparently, this has no effect on the Purchase Orders Preview window. You see, there is a user who goes into SOP and utilizes the SOP to POP link to create POs. In the Purchase Orders Preview window, she has a message at the bottom of the window saying "You do not have access to this document type". And, because of this, she cannot generate a PO. She has access to the items listed in the "Document T...