Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetProcessesByName isn't working

Tags:

c#

After searching alot regarding this issue, I'm still facing problems in checking whether the running process has finished or not. When the user hit the 'Go' button in the GUI, the program is running for about 5 seconds and closes. When it is finished, I want to do something (e.g., green mark in GUI).

My problem is the 'GetProcessesByName' apparently cannot see the program, which is strange, because I see it in the task manager. The program name is quartus_pgm.exe. See the following code, I've tried quartus_pgm, or quartus_pgm.exe, or quartus_pgm.exe32(as seen in the task manager) but nothing!

If I put 'cmd' it does see it (the quartus_pgm is envoked from the cmd), but it is not what i'm looking for. I've tried various methods:

Process[] targetProcess = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(processName));

or this one:

 Process[] processes = Process.GetProcessesByName("quartus_pgm");
                      if (processes.Length > 0)
                        // do something;

or this one:

foreach (var process in Process.GetProcessesByName("quartus_pgm.exe"))
                {
                    // do something;
                }
like image 499
roy.me Avatar asked Jun 12 '14 06:06

roy.me


2 Answers

Try remove .exe part.

foreach (var process in Process.GetProcessesByName("quartus_pgm"))
{
         // do something;
}

From here :

The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path

UPDATE

Try to list all of process in your machine, look for the quartus_pgm process name.

 foreach (var process in Process.GetProcesses())
 {
     Console.WriteLine(process.ProcessName);
 }
like image 93
Iswanto San Avatar answered Sep 20 '22 18:09

Iswanto San


Any chance that this method is case sensitive? If you loop through the processes, do you find it?

foreach (Process p in Process.GetProcesses())
            {
                if (p.ProcessName.ToLower() == "quartus_pgm")
                {

                }
            }
like image 40
Jesse Petronio Avatar answered Sep 20 '22 18:09

Jesse Petronio