Kill process if it takes too long to complete

Posted on 2005-04-24
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
    LVL 29

    Accepted Solution

    Have a look at 2 API's            CreateProcess API and Terminate Process API
    LVL 29

    Expert Comment

    You might want to look at         TimerQueue API as well

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    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…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now