close app without having form in foreground
-
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 IfPrivate 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 -
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 IfPrivate 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 SubWell 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.
-
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.
Notepad is an example, the name of the application is called Inventory, the one I want to close
-
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 IfPrivate 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 SubThe
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 theProcess.CloseMainWindow
method[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Notepad is an example, the name of the application is called Inventory, the one I want to close
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 -
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 Kreskowiakhello, 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
-
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
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 -
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 KreskowiakI 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
-
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
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 -
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 KreskowiakThank you for the time you dedicated, but I already solved the problem that it presented