I have an SFX WinRAR
autoxtraible file which runs a textfile using notepad.exe process, and the SFX file waits to receive an exitcode of notepad.exe to finish the SFX execution.
I would like to do a treekill
, kill all the processes openen by the SFX file, or in other words, I would like to reproduce this Batch command, in .NET
:
/t : Specifies to terminate all child processes along with the parent process, commonly known as a tree kill.
Taskkill /F /T /IM "SFX file.exe"
To kill a process I do this, in VBNET
:
''' <summary>
''' Kill a process specifying the process name.
''' </summary>
Private Sub Kill_Process(ByVal ProcessName As String,
Optional ByVal Recursive As Boolean = True)
ProcessName = If(ProcessName.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase),
ProcessName.Substring(0, ProcessName.LastIndexOf(".")),
ProcessName)
For Each p As Process In Process.GetProcessesByName(ProcessName)
p.Kill()
If Not Recursive Then Exit For
Next p
End Sub
Now, In C#
or VBNET
how I could identify the child processes opened by the SFX to kill them all at once?