Kill process if it takes too long to complete

Posted on 2005-04-24
Medium Priority
Last Modified: 2008-01-09
I have a program (A) which creates an instance of another program via GetObject (B). Then using the created (or found) object (B) from GetObject, I attempt to use VB to open a file in the newly created instance (B) and manipulate the file. Sometimes however, program (B) will stop responding due to any number of reasons that I am aware of, for example the file has embedded macros and program (B) pops up a window the user if they want to enable macros, or the file is corrupted and cannot be opened, or the file type is incorrect and cannot be opened. In each of these instances, program (B) pops up a window and waits for user interaction. I need program (A) to wait for a specified time, perhaps via a timer, and if the timer fires, close the current process and start a new one. The problem I have encountered is that the timer in a VB form evidently ceases to function or rather it pauses while it is waiting on the return value from the OLE interaction.

So, how can I kill a process (program B) if it is simply waiting for user input, from a timer in (program A).

I used this code in the timer

SendMessage Obj.hWnd, WM_DESTROY

but evidently the timer never fires while it is waiting on the other application to complete, even though it is enabled and set to a relatively short time frame.
Question by:Muerty
  • 2
LVL 29

Accepted Solution

nffvrxqgrcfqvvc earned 1000 total points
ID: 13853230
Have a look at 2 API's            CreateProcess API and Terminate Process API

LVL 29

Expert Comment

ID: 13853233
You might want to look at         TimerQueue API as well

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

862 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