I want to create a windows forms app and i want to terminate a program with it
system("tskill process");
doesnt't work nor calling a bat file doing this operation
I think I have to use TerminateProcess() TerminateProcess but I don't know where to put all the callback functions for example in a button with this code
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {}
Your callback looks to be in C++/CLI so I assume your using this language.
Here's a simple code to kill a process named MyProcess
array<Process^>^ Processes = Process::GetProcessesByName("MyProcess");
for each (Process^ P in Processes)
P->Kill();
Note that you may need to run your program in Administration mode. GetProcessesByName returns an array of Process, in case you have several instances of MyProcess you can kill all of them with this code.
To use the Process class, be sure to add this in your source file:
using namespace System::Diagnostics;