Kill Specific process in task manager

suresh_ed

Active member
Joined
May 19, 2008
Messages
27
Programming Experience
1-3
I want to close a process named yandytex.exe in task manager.

yandytex doesn't have sdk for .net

Please suggest how to close the process.


Regards,
Suresh
 
Have a look at usage for Process class. You should use CloseMainWindow method rather than Kill method.
 
Kill process

I done that using system.management namespace.

Using that we can kill any specific process.

Thank you friend
 
WMI Win32_Process class and Terminate method doesn't allow you to try and close the other process gracefully, it does the same as Kill. A better option if you don't want to use the .Net Process class is to use SendMessage API with WM_Close message, but Process class is of course the easiest option.
 
Sorry for the late response

Hello JohnH,

I am not using process class for opening that application. am using external script to open and use the application.

I checked the .Net process class thing is that we have to add the application to the process class then only we can close or kill.

Thanks for your suggestion !!!
 
That is not correct. You can use the Process class to list currently running processes, once you have the correct process reference you can ask it to close.
 
KillProcess class

I am using the following function to kill the specific process. But it couldn't able to find the process to kill.

calling KillProcess("yandytex.exe")


Dim prc() As Process
Dim ERROR_FILE_NOT_FOUND As Integer = 2
Dim ERROR_ACCESS_DENIED As Integer = 5
Try
prc = System.Diagnostics.Process.GetProcessesByName(ProcessName)
Dim eprc As IEnumerator = prc.GetEnumerator
eprc.Reset()

While eprc.MoveNext
Dim proc As Process = CType(eprc.Current, Process)
proc.Kill()
proc = Nothing
End While

eprc = Nothing
prc = Nothing

Catch e As System.ComponentModel.Win32Exception
If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
'MessageBox.Show(e.Message + ". Process not found.")
Throw New UnauthorizedAccessException(e.Message & ". Process not found.")
Else
If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
' Note that if your word processor might generate exceptions
' such as this, which are handled first.
'MessageBox.Show(e.Message + ". You do not have permission to kill this process.")
Throw New UnauthorizedAccessException(e.Message & ". You do not have permission to kill this process.")
End If
End If
End Try

Please Suggest
 
Friendly names doesn't contain file extensions. I would rather use a For-Each loop:
VB.NET:
For Each p As Process In Process.GetProcessesByName("notepad")
    Try
        If p.CloseMainWindow() Then
            MessageBox.Show("nice process close")
        Else
            p.Kill()
            MessageBox.Show("oops, had to kill it :(")
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try            
Next
Remember to use Code blocks when posting code, it makes the post readable. It is just one click of the Code button in message editor.
 
Back
Top