using namespace System::Diagnostics;

 

Create Process

	if (File::Exists("C:\\Program Files\\Some Folder\\SomeApp.exe"))
	{
		Process1 = gcnew Process();
		Process1->StartInfo->FileName = "C:\\Program Files\\Some Folder\\SomeApp.exe";
		Process1->StartInfo->Arguments = "";
		Process1->Start();
		Process1->WaitForInputIdle();
	}

 

Is Process Active

	if ((Process1 != nullptr) && (!Process1->HasExited))
	{

 

Close The Process

	if ((Process1 != nullptr) && (!Process1->HasExited))
	{
		//Process1->CloseMainWindow();
		//Process1->Close();
		Process1->Kill();			//Use this instead of Close or CloseMainWindow as they leave the process active in windows task manager and stop us from beign able to open Control Manager again
		Process1->WaitForExit();	//Can use this if we want to
	}
	Process1 = nullptr;

Has user selected other process


	System::IntPtr WinHandle = GetForegroundWindow();
	if (WinHandle == Process1->MainWindowHandle)
	{

Is A Process Already Running


	array<Process^> ^CurrentProcesses = System::Diagnostics::Process::GetProcessesByName("some_process_name");
	if (CurrentProcesses->Length > 0)
	{
		MessageBox::Show(L"Process is running:" , L"Running", MessageBoxButtons::OK, MessageBoxIcon::Information);
	}

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.