Question Kill Process with Part of Process Name

Status
Not open for further replies.

wiseindian

New member
Joined
Aug 21, 2013
Messages
2
Programming Experience
Beginner
I have to kill a process (an exe file) that does not have a distinctive name. All I know are the first two chars of its name for eg "3D". I have tried to use wildcards (3d*) but these do not work.
I have managed to verify that the process is running but I can't figure out how to search through the processes and then kill the process which begins with "3D".

Here si my code:
'-- get a collection of processes running
Dim nameProcess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
For Each p As Process In Process.GetProcesses()
Debug.WriteLine(p.ProcessName)
Next
' this is the process check function
threeD = 3D 'I have declared this as string before in the code
If IsProcessRunning(threeD) = True Then
MsgBox("3D Found")
End If

I also used this to loop through the processes but the wild card does not work:
Dim proc() As Process = Process.GetProcessesByName("3D*")
For Each temp As Process In proc
temp.Kill()
Next
 

wiseindian

New member
Joined
Aug 21, 2013
Messages
2
Programming Experience
Beginner
I managed to come up with a working solution:
Dim nameProcess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
For i = 0 To nameProcess.Length - 1
If nameProcess(i).ProcessName.StartsWith("3D") Then
Dim exeName As String = nameProcess(i).ProcessName
Dim proc() As Process = Process.GetProcessesByName(exeName)
For Each temp As Process In proc
temp.Kill()
Next
End If
Next
 

ident

Member
Joined
Apr 30, 2012
Messages
12
Location
Cambridge
Programming Experience
3-5
PHP:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles MyBase.Load

        Dim procs =
            From p
            In Process.GetProcesses
            Where New System.Text.RegularExpressions.Regex("^3D.+$").IsMatch(p.ProcessName)
            Select p

        Array.ForEach(procs.ToArray, Sub(p) p.Kill())
    End Sub

End Class
 
Status
Not open for further replies.
Top Bottom