The two subroutines below are examples of one approach. These will not work
on Win95/98 systems unless they've added WMI but they should work fine with
WinXP or Win2K.
The subroutine "RunOneNotepad" checks the list of running processes and
determines if any are named notepad.exe (I don't have kobra.exe so I tested
with notepad.exe which I do have). If none are found, it launches a new
process and documents the process ID ("PID") in cell A1 of Sheet1.
The subroutine "KillSpecificPID" extracts the PID from cell A1 (if there is
one there) and kills the process with that ID if it is still running.
___________________________________
Sub RunOneNotepad()
Dim runningNotepad As Boolean
runningNotepad = False
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMI.ExecQuery _
("Select * from Win32_Process")
For Each objProcess In colProcess
If objProcess.Name = "NOTEPAD.EXE" Then
runningNotepad = True
End If
Next
If runningNotepad = False Then
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2:Win32_Process")
objWMI.Create "notepad.exe", Null, Null, intProcessID
Sheets(1).Cells(1, 1).Value = intProcessID
End If
runningNotepad = False
Set objWMI = Nothing
End Sub
Sub KillSpecificPID()
intPID = Sheets(1).Cells(1, 1).Value
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMI.ExecQuery _
("Select * from Win32_Process Where ProcessID = " & intPID & "")
For Each objProcess In colProcess
objProcess.Terminate
Next
End Sub
Steve