Most efficient way to see if a process is still running in C#?

Discussion in 'Mixed Languages' started by CODYQX4, Oct 8, 2011.

  1. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,814
    45,630
    150
    #1 CODYQX4, Oct 8, 2011
    Last edited: Apr 15, 2019
    .
     
  2. Daz

    Daz MDL Developer / Admin
    Staff Member

    Jul 31, 2009
    9,528
    66,782
    300
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,814
    45,630
    150
    #3 CODYQX4, Oct 8, 2011
    Last edited: Apr 15, 2019
    (OP)
    .
     
  4. Daz

    Daz MDL Developer / Admin
    Staff Member

    Jul 31, 2009
    9,528
    66,782
    300
    The longer the wait time the better IMO. That's if it's not critical for the file to be running within even 5 minutes?

    You're right that my suggestion wouldn't work in your case. If the keygen was your own executable that was getting stopped then it would probably work but as it's not I think your current method would be the most efficient.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,814
    45,630
    150
    #5 CODYQX4, Oct 8, 2011
    Last edited: Apr 15, 2019
    (OP)
    .
     
  6. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,118
    120
    #6 Josh Cell, Oct 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Well, You can use it to view if process it running and Kill it :

    Code:
    public bool ProcessFinderAndKiller(string process)
    {
            foreach (Process clsProcess in Process.GetProcesses()) {
                    if (clsProcess.ProcessName.StartsWith(process))
                    {
                            //kill process if it is running
                            clsProcess.Kill();
                            //return true if process still running
                            return true;
                    }
            }
            //return false if process still not running
            return false;
    }
    Modding to find any:

    Code:
    public bool ProcessFinder(string process)
    {
            foreach (Process clsProcess in Process.GetProcesses()) {
                    if (clsProcess.ProcessName.StartsWith(process))
                    {
                            //return true if process still running
                            return true;
                    }
            }
            //return false if process still not running
            return false;
    }
    Bool functions, return true or false, you can use:

    Code:
    ProcessFinder("winamp"); [ aways without .exe ]
    
    ProcessFinderAndKiller("winamp"); [ aways without .exe ]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    750
    127
    30
    @codyqx4, so far i've not had any trouble at all using your microsoft toolkit that uses vbc.exe to run kms. it's not disappeared ever, and both microsoft security essentials and avast even though they detect it when it runs as malicious they never notify the user exactly what the file/process is only the pid. but if vbc.exe is put on the exceptions/exclusions lists it never even notifies that anything is wrong at all.

    i don't think there is any need for you to make anything other than what you have honestly. the original kmsemulator, and this new kms run through vbc are perfect how they are. and even if something new you develop uses roughly no memory at all, it's still better to have something run once at startup and then stop as opposed to having something running all the time in the background. it's like de-evolution in the process i think...

    :cool:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,814
    45,630
    150
    #8 CODYQX4, Oct 8, 2011
    Last edited: Apr 15, 2019
    (OP)
    .
     
  9. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    750
    127
    30
    i see, sorry i misinterpreted what you asking above then :cool:

    keep up the good work :worthy:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...