Re: [2005] Tricky Question
Taskkill is a Windows commandline utility. If you search Windows Help and Support from the Start menu it gives you the syntax and some examples, including one using Notepad. I'd not be inclined to go that route though. If you're using VB.NET then use VB.NET. Use Process.GetProcessesByName to get a list of all runing processes with the specified name, then Process.CloseMainWindow to try to end the process gracefully, then Process.Kill to force the process to exit if it didn't repond to CloseMainWindow for whatever reason. Reasons would be that the process didn't have a main window or it was waiting for input from the user, like a prompt to save any pending changes. For that reason you should wait for a short time to allow the process to exit naturally by its own action or that of the user.
VB Code:
For Each proc As Process In Process.GetProcessesByName("process name here")
proc.CloseMainWindow() 'ask the process to exit.
proc.WaitForExit(10000) 'wait up to 10 seconds.
If Not proc.HasExited Then
proc.Kill() 'force the process to exit.
End If
Next proc
Re: [2005] Tricky Question
Ok for this part ("process name here"), how do i have the user put in the process name via the interface. would i simply put txtinput.text, and have the user type in the process name that will be closed?
Re: [2005] Tricky Question
It's just a string so it's up to you how you get that string. The two most likely methods would be to have the user enter it in a TextBox or you could get the name of all running processes and display them in a ComboBox.
Re: [2005] Tricky Question
I know how to get the processes, i put them in a list box, but if i wanted the user to type in a textbox to stop that process or simply right click it, how would i tell it to cancel that one process
Re: [2005] Tricky Question
I'm not sure I'm following you. You're saying that you have a list of running processes in a ListBox and you want to know how to end one of them, right? If so then you'd just get the name string from the ListBox, either by casting an item as String or using the GetItemText method, and place it where I've put "process name here". One thing to note is that if you want to identify individual processes from a number with the same name then you'd have to have get the process ID in the first place too. You could quite easily create a list of process IDs and names and bind it to a ListBox using the name as the DisplayMember and the ID as the ValueMember. If you do that though, make sure you check that that PID is still active with the same name when you try to end it as there is no guarantee that things won't have changed in the interim.
Re: [2005] Tricky Question
Here try this for the input of the process by text box. You will have to know of the name of the process though (ex.. "notepad.exe" not just "notepad").
For Each proc As Process In Process.GetProcessesByName(textbox.text)
proc.CloseMainWindow() 'ask the process to exit.
proc.WaitForExit(10000) 'wait up to 10 seconds.
If Not proc.HasExited Then
proc.Kill() 'force the process to exit.
End If
Next proc