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);
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.