Solved

terminate a process (Vb.NET 1.1)

Posted on 2006-06-30
2
1,751 Views
Last Modified: 2008-07-05
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
0
Comment
Question by:muskad202
2 Comments
 

Expert Comment

by:king_villy
ID: 17022421
Use this code , by using this code you can terminate Process by name , by id both of style s
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(target_hwnd, target_process_id)
        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_process_handle, 2) = 0) Then
            MessageBox.Show("Error terminating process")
        Else
            MessageBox.Show("Process terminated")
        End If

        ' Close the process.
        CloseHandle(target_process_handle)
End Sub
0
 
LVL 8

Accepted Solution

by:
kaliyugkaarjun earned 30 total points
ID: 17022807
HEre is a link showing example of how to terminate a process in  VB.net ...just go thr it.

http://www.vb-helper.com/howto_net_terminate_process.html
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now