First of all, you parse each processname to upper case and then compare it to a normal case string. That won't ever be true. Second ProcessName returns the name of the process only, without the extension, and without the directory info. Thus a programme that is called
myProgramme.exe
will return
myProgram
without the extension. Try something liek this:-
Process[] myProcesss;
myProcesss = Process.GetProcesses();
bool isRunning = false;
foreach (Process myProcess in myProcesss)
{
if (myProcess.ProcessName.Equals("myProgramme",StringComparison.InvariantCultureIgnoreCase ))
{
isRunning = true;
}
}
string message = isRunning ? "Running" : "Not Running";
MessageBox.Show(message);
obviously substitute MessageBox for Console.WriteLine for a console app and myProgramme for the name of your programme.
Hope this helps