-
Dec 19th, 2010, 09:33 AM
#1
Closing an External Process
VB version here.
You can use the .NET Process class to close an external application. First you must create a Process object that represents the application. You can then call Kill on that Process to force the application to close. That's the only way to close applications that don't have a GUI but, for those that do, it's better to call CloseMainWindow first and only call Kill as a last resort. It's like the difference between just throwing someone out and asking them to leave first. CloseMainWindow gives the application a chance to clean up before exiting, while Kill just removes it from memory. E.g.
csharp Code:
private void CloseProcessesByName(string processName) { foreach (Process p in Process.GetProcessesByName(processName)) { // Ask nicely for the process to close. p.CloseMainWindow(); // Wait up to 10 seconds for the process to close. p.WaitForExit(10000); if (! p.HasExited) { // The process did not close itself so force it to close. p.Kill(); } // Dispose the Process object, which is different to closing the running process. p.Close(); } }
The process name is what gets displayed in Windows Task Manager.
NOTE: Code converted using Instant C# by Tangible Software Solutions.
-
Feb 17th, 2011, 04:45 AM
#2
Re: Closing an External Process
That's nice clean and simple compared to say the lines and lines you used to need for VB6.
Last edited by Jmacp; Feb 17th, 2011 at 05:54 AM.
-
Feb 17th, 2011, 05:16 PM
#3
Re: Closing an External Process
Cool is it ok if i can use this cos i am going to make a process viewer.
thanks for shareing.
-
Feb 23rd, 2015, 11:47 PM
#4
New Member
Re: Closing an External Process
Ok , Thanks To share ...
..
I'm try to kill some program .. but that's no work !!
What's problem ?
-
Feb 23rd, 2015, 11:50 PM
#5
Re: Closing an External Process
Originally Posted by a_almisery
Ok , Thanks To share ...
..
I'm try to kill some program .. but that's no work !!
What's problem ?
How could anyone answer that question based on the information you have provided?
-
Feb 24th, 2015, 12:00 AM
#6
Fanatic Member
Re: Closing an External Process
Originally Posted by jmcilhinney
How could anyone answer that question based on the information you have provided?
I'm pretty sure he's following your posts around and spamming them. He's the same one that commented on my thread that you just replied to.
If ive helped, RATE my post.
If your thread is solved, and you got your answer, mark this thread Resolved.
There is no other forum like VBFORUMS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|