Results 1 to 3 of 3

Thread: Kill Process + VB.NET

Hybrid View

  1. #1

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Kill Process + VB.NET

    Hi I am using the following code to get the list of all the running processes.

    VB Code:
    1. Imports System.Diagnostics
    2.  
    3.         Dim proc As Process
    4.  
    5.         ListBox1.Items.Clear()
    6.  
    7.         For Each proc In Process.GetProcesses
    8.             ListBox1.Items.Add(proc.ProcessName)
    9.         Next

    Now I can't find a way to kill the process selected in the listbox. I think it fills the listbox with the name of exe.

    Any idea...???

    Cheers.

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    To ask the process nicely to close use
    VB Code:
    1. If Process.CloseMainWindow Then
    2.    '\\ Process closed itself
    3. End If

    To force it to die use:
    VB Code:
    1. Process.Kill

    Remarks
    Kill forces a termination of the process, while CloseMainWindow only requests a termination. When a process with a graphical interface is executing, its message loop is in a wait state. The message loop executes every time a Windows message is sent to the process by the operating system. Calling CloseMainWindow sends a request to close to the main window, which, in a well-formed application, closes child windows and revokes all running message loops for the application. The request to exit the process by calling CloseMainWindow does not force the application to quit. The application can ask for user verification before quitting, or it can refuse to quit. To force the application to quit, use the Kill method. The behavior of CloseMainWindow is identical to that of a user closing an application's main window using the system menu. Therefore, the request to exit the process by closing the main window does not force the application to quit immediately.

    Data edited by the process or resources allocated to the process can be lost if you call Kill. Kill causes an abnormal process termination and should be used only when necessary. CloseMainWindow enables an orderly termination of the process and closes all windows, so it is preferable for applications with an interface. If CloseMainWindow fails, you can use Kill to terminate the process. Kill is the only way to terminate processes that do not have graphical interfaces.

    You can call Kill and CloseMainWindow only for processes that are running on the local computer. You cannot cause processes on remote computers to exit. You can only view information for processes running on remote computers.
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  3. #3

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695
    Thanks Merrion I already read that in MSDN and then I also found that ones what I want to terminate haven't got any window so it's a background process.

    So I guess I need to use the kill method but it won't work and I am getting an error which basically mean a type mismatch.

    I have made sure that the variable is declared as a process.

    Also if someone can show me how to use Try and Catch system with this one. I mean try closing it with close window and if it doesn't work then force to kill. since I just started using VB.NET I can't make it work right.

    Cheers.

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