Kill shelled process

B

Brian

I have developed an app that creates a script file, shells out to FTP.exe to
run the script (which variously dir's, downloads, or deletes files via FTP)
and waits for the process to finish before continuing.

Occasionally, FTP.exe will hang. In this case, I must manually kill the
FTP.exe process in order for my program to continue execution. Is there any
way to create a function that kills the shelled process after a timeout? Here
are two lines from my module that manages the shell process:

Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long,
ByVal dwMilliseconds As Long) As Long

ret& = WaitForSingleObject(proc.hProcess, Infinite)

I have not explored the dwMilliseconds argument here. If I change it from
"Infinite" to an integer so that my application continues after a timeout
period, VBA would (presumably) continue but leave the hung shelled process
running, and this could potentially create a lot of other problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top