Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Taf Taf is offline
external usenet poster
 
Posts: 2
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
Taf Taf is offline
external usenet poster
 
Posts: 2
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ending in Macros Evil with a K[_2_] Excel Worksheet Functions 2 May 18th 09 10:37 PM
week ending peter Excel Worksheet Functions 4 April 3rd 08 03:31 AM
Week ending [email protected] Excel Worksheet Functions 3 November 1st 05 04:52 PM
Ending zero RAB Excel Discussion (Misc queries) 3 August 25th 05 06:09 PM
Ending Sub Paul Excel Programming 3 October 1st 04 07:48 PM


All times are GMT +1. The time now is 09:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"