Solved

terminate a process (Vb.NET 1.1)

Posted on 2006-06-30
2
1,749 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

14 Experts available now in Live!

Get 1:1 Help Now