Results 1 to 3 of 3

Thread: Detect running process and shut it down

  1. #1

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    Detect running process and shut it down

    Hey,

    I was kind of surprised to find no results to my question on a search in VB.NET - very surprising to see no one has wanted this, or was i just searching wrong?

    Well, my problem is this. I have a program that renames an exe, but of course if the exe is open it wont work.

    So i need some code to detect whether the exe is running, and if it is, shut it down so that i can rename it.

    This is a really important aspect to my program as it is very likely that the exe is open at the time.

    Thanks very much, I'm sure i wrote something like this in vb6. I'll try to see if i still have it.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You can query a process by it's name . Here I'm shutting down an application named "matrix" .

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal
    2. e As System.EventArgs) Handles Button1.Click
    3.  
    4.         Dim p As Process
    5.         For Each p In Process.GetProcesses
    6.             Me.ListBox1.Items.Add(p.ProcessName)
    7.             If p.ProcessName = "matrix" Then
    8.                 p.Kill()
    9.                 If p.HasExited Then
    10.                     MessageBox.Show("Process was terminated successfully")
    11.                 End If
    12.             End If
    13.         Next
    14.  
    15. End Sub

  3. #3

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    thanks very much.

    that looks way easier than what i thought it would! I was expecting some complex api calls.

    i'll try it later, i'm very depressed at the moment tho.

    thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width