Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Shell still running?

Hi,

I wonder if it's possible to check if an external command is still running,
using the Shell-function.

Here's my code (vCmd = dos-program):

vID = Shell(vCmd, vbMinimizedNoFocus)

is it possible to use vID in order to see if the dos-command is still open?

Thanks,
Jos Vens


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Shell still running?

Jos,

Here is an example of something you can modify that should work. In my
example, the first message box was used to make sure I gave enough time for
Notepad to actually open before the remaining code checked for the process
ID. In practice, you probably won't need it. I also had Notepad open in a
normal window with focus for purposes of testing but you can easily modify.

'----------------------------------------------
Sub StartProcessThenCheck()
Dim objWMI As Object
Dim colProcesses As Object
Dim objProcess As Object
Dim vID As Variant

vID = Shell("C:\Windows\Notepad.exe", 1)

MsgBox "A new notepad process has been started"

Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cim v2")
Set colProcesses = objWMI.ExecQuery _
("Select * from Win32_Process")

For Each objProcess In colProcesses
If objProcess.ProcessID = vID Then
MsgBox "The instance of Notepad you just started is still running"
End If
Next objProcess

Set objWMI = Nothing
Set colProcesses = Nothing
Set objProcess = Nothing
End Sub


'---------------------------------------------

Steve Yandl



"Jos Vens" wrote in message
...
Hi,

I wonder if it's possible to check if an external command is still
running, using the Shell-function.

Here's my code (vCmd = dos-program):

vID = Shell(vCmd, vbMinimizedNoFocus)

is it possible to use vID in order to see if the dos-command is still
open?

Thanks,
Jos Vens



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
Running A Shell Command In VBA R Tanner Excel Programming 1 December 4th 08 10:06 PM
Running Shell Jeff Excel Discussion (Misc queries) 0 January 28th 08 04:50 PM
running two separate commands in same Shell GPDynamics Excel Programming 3 May 30th 05 10:58 PM
running commands from hte shell Ruthless Dog Excel Programming 4 May 17th 05 02:38 PM
shell command running very slow TTD Excel Programming 0 December 1st 04 09:43 AM


All times are GMT +1. The time now is 02:23 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"