View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl[_3_] Steve Yandl[_3_] is offline
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