[Rookie] How to terminate a specific running application?

Hello there, this is my first post in this forum. Recently i started learning c++ from this E-book http://www.amazon.in/Ivor-Hortons-Beginning-Visual-2012/dp/1118368088 . From what the author mentioned i learned that visual c++ use managed c++ rather than native language. I dont know if this will make a significant difference in how the program is coded. So now am learning to code console apps using visual c++ 2012 IDE. I wanted help with making a console app which can terminate a specific app shown in the task manager. When i tried googling most were topics on Process ID's and so on .. Someone kindly help me with this.

Thank you :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

int main()
{
   // terminate all instances of notepad.exe
   // http://msdn.microsoft.com/en-us/library/z3w4xdc9(v=vs.110).aspx
   for each( Process^ proc in Process::GetProcessesByName( "notepad" ) ) 
   {
       // http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill(v=vs.110).aspx
       try { proc->Kill() ; } 
       catch( Exception^ e ) { Console::WriteLine( e->Message ) ; }
   }
}
Thank you :)

btw i got a question... is this using a win API function to terminate a process?
> is this using a win API function to terminate a process?

No. This uses the CLI Framework Library. (Which internally would be using the native API)
Topic archived. No new replies allowed.