3 Replies - 776 Views - Last Post: 21 August 2013 - 06:09 AM Rate Topic: -----

#1 wiseindian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-August 13

Kill Process where I Have only Part of the Process Name

Posted 21 August 2013 - 01:34 AM

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".

How do I find the process name and kill it.

Here's my code where I check that the process is running but then what? I tried using the wildcard but it does not work.
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 tried this:
Dim proc() As Process = Process.GetProcessesByName("3D*")
        ' closes PowerPoint files
        For Each temp As Process In proc
            temp.Kill()
        Next


Is This A Good Question/Topic? 0
  • +

Replies To: Kill Process where I Have only Part of the Process Name

#2 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 966
  • Joined: 09-May 09

Re: Kill Process where I Have only Part of the Process Name

Posted 21 August 2013 - 04:01 AM

Found this, should be worth a go

Dim procExists as Boolean = Process.GetProcesses().Any(Function(p) p.Name.Contains(processName))


Was This Post Helpful? 0
  • +
  • -

#3 wiseindian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-August 13

Re: Kill Process where I Have only Part of the Process Name

Posted 21 August 2013 - 05:31 AM

Sorry deery5000 - that doesn't help. Does anyone know how I can search the process arrays and get back just one process using a kind of wildcard?
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Kill Process where I Have only Part of the Process Name

Posted 21 August 2013 - 06:09 AM

View Postwiseindian, on 21 August 2013 - 06:31 AM, said:

Sorry deery5000 - that doesn't help. Does anyone know how I can search the process arrays and get back just one process using a kind of wildcard?

The first thing you should do is to have a look at one of our debugging tutorials Here and Here. Single-stepping through your code would have shown you that you already got your process array filled on line 1 of your first code sample, and that your For Each loop was not returning anything.

All you need to do after getting the array filled is to loop through the nameProcess array and check for the presence of your search string; something like this:

        Dim nameProcess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
        For i = 0 To nameProcess.Length - 1
            If nameProcess(i).ProcessName.StartsWith("3D") Then
                ' Do whatever you want with this info
                TextBox1.Text &= nameProcess(i).ProcessName & vbNewLine
            End If
        Next


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1