Results 1 to 7 of 7

Thread: How to End process in vb.net

  1. #1

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Arrow How to End process in vb.net

    For example "C:\myapp\app.exe"
    I know this code Process.Start("C:\myapp\app.exe") but this only starts the file and does not end it. How can i end it thank you in advance
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  2. #2

  3. #3
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: How to End process in vb.net

    Quote Originally Posted by Pc_Not_Mac View Post
    For example "C:\myapp\app.exe"
    I know this code Process.Start("C:\myapp\app.exe") but this only starts the file and does not end it. How can i end it thank you in advance
    Again, this is one of those situations that all you needed to do was utilize Google.

    You'll always want to try CloseMainWindow first and then call .Kill so that it's only done if needed.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    Hyperactive Member Philly0494's Avatar
    Join Date
    Apr 2008
    Posts
    485

    Re: How to End process in vb.net

    Code:
    For Each p As Process In Process.GetProcessesByName("app")
             p.Kill()
    Next

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: How to End process in vb.net

    What Philly0494 means is:

    VB.NET Code:
    1. For Each p As Process In Process.GetProcessesByName("app")
    2.     If p Is Nothing Then Return
    3.     If Not p.CloseMainWindow() Then p.Kill()
    4. Next

    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6

  7. #7
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: How to End process in vb.net

    Quote Originally Posted by cicatrix View Post
    isn't CloseMainWindow redundant? Or it leaks?
    I'm not sure what you're asking exactly.

    But the reason you'd send CloseMainWindow first, is because .Kill could cause issues.

    Kill:

    Quote Originally Posted by MSDN
    Immediately stops the associated process.
    If that process is in the middle of doing something important, you could cause additional problems and so it should be a last resort.

    CloseMainWindow:

    Quote Originally Posted by MSDN
    Closes a process that has a user interface by sending a close message to its main window.
    By sending a message to the application, it has the opportunity to stop or do whatever it needs to, to make sure everything else continues to run smoothly.

    Now, I could be terribly wrong, but that's what I've inferred from the documentation and what I've read around VBF.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

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