muskad202
asked on
terminate a process (Vb.NET 1.1)
Hi!
Given the process Id, how can I forcefully terminate a process? I tried Process.GetProcessById(id) .Kill(), but i get an "Access Denied" exception for a number of processes, even though I can terminate them via Task Manager.
Thanks,
muskad202
Given the process Id, how can I forcefully terminate a process? I tried Process.GetProcessById(id)
Thanks,
muskad202
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hope it will help you
==========================
public Sub Terminator_Sub
Dim target_hwnd, target_process_id, target_process_handle As Integer
' Get the target's window handle.
target_hwnd = FindWindow(vbNullString, "Name of Terminated Process")
If (target_hwnd = 0) Then
MessageBox.Show("Error finding target window handle")
Exit Sub
End If
' Get the process ID.
target_process_id = 0
GetWindowThreadProcessId(t
If (target_process_id = 0) Then
MessageBox.Show("Error finding target process ID")
Exit Sub
End If
' Open the process.
target_process_handle = OpenProcess( _
SYNCHRONIZE Or PROCESS_TERMINATE, _
0, target_process_id)
If (target_process_handle = 0) Then
MessageBox.Show("Error finding target process handle")
Exit Sub
End If
' Terminate the process.
If (TerminateProcess(target_p
MessageBox.Show("Error terminating process")
Else
MessageBox.Show("Process terminated")
End If
' Close the process.
CloseHandle(target_process
End Sub