ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ending an External App from VBA (https://www.excelbanter.com/excel-programming/326290-ending-external-app-vba.html)

Taf

Ending an External App from VBA
 
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

Jake Marx[_3_]

Ending an External App from VBA
 
Hi MT,

I think this will do what you need:

http://msdn.microsoft.com/library/de...ateprocess.asp

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


Taf wrote:
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



Taf

Ending an External App from VBA
 
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" wrote in message ...
Hi MT,

I think this will do what you need:

http://msdn.microsoft.com/library/de...ateprocess.asp

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


Taf wrote:
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


Jake Marx[_3_]

Ending an External App from VBA
 
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]


Taf wrote:
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" wrote in message
...
Hi MT,

I think this will do what you need:

http://msdn.microsoft.com/library/de...ateprocess.asp

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


Taf wrote:
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




All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com