Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. close app without having form in foreground

close app without having form in foreground

Scheduled Pinned Locked Moved Visual Basic
data-structureshelptutorial
10 Posts 4 Posters 26 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Benjamindh
    wrote on last edited by
    #1

    hello everyone, I have the following problem, it happens that I want to close an example application: Notepad, but the code only works for me if I have the form in the foreground if it is minized, do not close the application, I want to close the application no matter what window I am using , this is my code.

    If e.KeyCode = Keys.Escape Then
    KilleInventory()
    End If

    Private Sub KilleInventory()
    Dim processesByName() As Process = Process.GetProcessesByName("Inventory")
    Dim array() As Process = processesByName
    For Each process As Process In array
    process.Kill()
    Next process
    End Sub

    Richard Andrew x64R Richard DeemingR 2 Replies Last reply
    0
    • B Benjamindh

      hello everyone, I have the following problem, it happens that I want to close an example application: Notepad, but the code only works for me if I have the form in the foreground if it is minized, do not close the application, I want to close the application no matter what window I am using , this is my code.

      If e.KeyCode = Keys.Escape Then
      KilleInventory()
      End If

      Private Sub KilleInventory()
      Dim processesByName() As Process = Process.GetProcessesByName("Inventory")
      Dim array() As Process = processesByName
      For Each process As Process In array
      process.Kill()
      Next process
      End Sub

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Well one reason it's not closing Notepad is that you're calling GetProcessesByName("Inventory").

      The difficult we do right away... ...the impossible takes slightly longer.

      B 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Well one reason it's not closing Notepad is that you're calling GetProcessesByName("Inventory").

        The difficult we do right away... ...the impossible takes slightly longer.

        B Offline
        B Offline
        Benjamindh
        wrote on last edited by
        #3

        Notepad is an example, the name of the application is called Inventory, the one I want to close

        D 1 Reply Last reply
        0
        • B Benjamindh

          hello everyone, I have the following problem, it happens that I want to close an example application: Notepad, but the code only works for me if I have the form in the foreground if it is minized, do not close the application, I want to close the application no matter what window I am using , this is my code.

          If e.KeyCode = Keys.Escape Then
          KilleInventory()
          End If

          Private Sub KilleInventory()
          Dim processesByName() As Process = Process.GetProcessesByName("Inventory")
          Dim array() As Process = processesByName
          For Each process As Process In array
          process.Kill()
          Next process
          End Sub

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          The Process.Kill method[^] is a method of last resort. It immediately terminates the specified process without giving it a chance to clean up, and could potentially lead to system corruption. If you want to close the application properly, you should start with the Process.CloseMainWindow method[^] instead.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • B Benjamindh

            Notepad is an example, the name of the application is called Inventory, the one I want to close

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Use the name of the executable you're trying to stop, without the ".exe" extension.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            B 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Use the name of the executable you're trying to stop, without the ".exe" extension.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              B Offline
              B Offline
              Benjamindh
              wrote on last edited by
              #6

              hello, I see your message I was a bit sick, it happens that the code I have works but as long as I don't have the form in the foreground it doesn't close the program that I want to close, to close the program I always have to have the form in the foreground and that's it I don't want

              D 1 Reply Last reply
              0
              • B Benjamindh

                hello, I see your message I was a bit sick, it happens that the code I have works but as long as I don't have the form in the foreground it doesn't close the program that I want to close, to close the program I always have to have the form in the foreground and that's it I don't want

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                One has nothing to do with the other. There's something else going on here you're not telling us about. It does not matter if your app, or the app you want to kill, is in the foreground in order to kill the process.

                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                Dave Kreskowiak

                B 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  One has nothing to do with the other. There's something else going on here you're not telling us about. It does not matter if your app, or the app you want to kill, is in the foreground in order to kill the process.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  B Offline
                  B Offline
                  Benjamindh
                  wrote on last edited by
                  #8

                  I tell you I have a program for online connection, it runs the MAME emulator online, 3 instances open, one the main menu, the second the KAILLERA and the third the game window already executed, then when you press the ESC key the game window will close but it remains it still activates the MAME main menu window but if I go to the main form and press the ESC key it completely closes the emulator

                  D 1 Reply Last reply
                  0
                  • B Benjamindh

                    I tell you I have a program for online connection, it runs the MAME emulator online, 3 instances open, one the main menu, the second the KAILLERA and the third the game window already executed, then when you press the ESC key the game window will close but it remains it still activates the MAME main menu window but if I go to the main form and press the ESC key it completely closes the emulator

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    What does "I have a program for online connection" mean? How does this "online" thing relate to what code is running on which machines?

                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                    Dave Kreskowiak

                    B 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      What does "I have a program for online connection" mean? How does this "online" thing relate to what code is running on which machines?

                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                      Dave Kreskowiak

                      B Offline
                      B Offline
                      Benjamindh
                      wrote on last edited by
                      #10

                      Thank you for the time you dedicated, but I already solved the problem that it presented

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups