Ending an External App from VBA

T

Taf

I am using the VBA Shell function, available in Excel, to run a DOS
Batch file.
Previous posts have shown me how to make Excel wait for the batch file
to comlete by using the Windows API and monitoring for the status of
the Process ID.

There are circumstances where I would like to kill the batch file
before it is completed. (Timeout or uer interupt for instance)

Is there a way to get Excel to kill the a previosly 'shelled' process
without having to wait for it to complete normally?

Many thanks
MT
 
T

Taf

Jake

This is exactly what I was after and it works fine when ending
'windows' apps.

The problem I have is that I am trying to kill a shelled DOS 'PING'
command, such as :

lTaskID = Shell("COMMAND /C PING 192.168.0.11 > C:\PING.TXT",
vbminimizedNoFocus)

In order for the result to successfully 'pipe' to the text file I need
to run the ping within a new instance of COMMAND. But it seems that
this means that the command keeps going and will not end using the
process you have pointed me towards.

(Incidently, this is the same if attempt to 'close' the Dos box
manually by right clicking it on the taskbar and selecting close - I
assume that this also uses the same TerminateProcess call)

Is there a way around this so that the DOS Ping command will end
immediately? or could you recommend a different way of initiating the
Ping that would allow me to end it from within VBA?

Thanks Again
MT

Jake Marx said:
Hi MT,

I think this will do what you need:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminateprocess.asp

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

I am using the VBA Shell function, available in Excel, to run a DOS
Batch file.
Previous posts have shown me how to make Excel wait for the batch file
to comlete by using the Windows API and monitoring for the status of
the Process ID.

There are circumstances where I would like to kill the batch file
before it is completed. (Timeout or uer interupt for instance)

Is there a way to get Excel to kill the a previosly 'shelled' process
without having to wait for it to complete normally?

Many thanks
MT
 
J

Jake Marx

Hi MT,

What is the purpose of the ping request? Are you just trying to see if you
can get a response from the IP? The Ping command should stop on its own
after 4 requests, or does that take longer than you want to wait in your
code? If so, you could use the -n option with a value of 1, which will
perform only 1 ping request.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Jake

This is exactly what I was after and it works fine when ending
'windows' apps.

The problem I have is that I am trying to kill a shelled DOS 'PING'
command, such as :

lTaskID = Shell("COMMAND /C PING 192.168.0.11 > C:\PING.TXT",
vbminimizedNoFocus)

In order for the result to successfully 'pipe' to the text file I need
to run the ping within a new instance of COMMAND. But it seems that
this means that the command keeps going and will not end using the
process you have pointed me towards.

(Incidently, this is the same if attempt to 'close' the Dos box
manually by right clicking it on the taskbar and selecting close - I
assume that this also uses the same TerminateProcess call)

Is there a way around this so that the DOS Ping command will end
immediately? or could you recommend a different way of initiating the
Ping that would allow me to end it from within VBA?

Thanks Again
MT

Jake Marx said:
Hi MT,

I think this will do what you need:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminateprocess.asp

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

I am using the VBA Shell function, available in Excel, to run a DOS
Batch file.
Previous posts have shown me how to make Excel wait for the batch
file to comlete by using the Windows API and monitoring for the
status of the Process ID.

There are circumstances where I would like to kill the batch file
before it is completed. (Timeout or uer interupt for instance)

Is there a way to get Excel to kill the a previosly 'shelled'
process without having to wait for it to complete normally?

Many thanks
MT
 

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