0

I want to disable a process in operating system while my exe is running. If former process running when my process start it will be disable and after my exe closed it will continue to run.

I am using C#, I tried process.kill method in System.Diagnostics namespace but that function closes application permanently.

grizzthedj
  • 7,131
  • 16
  • 42
  • 62
  • 1
    kill stops execution, you could just restart it - but it depends, what exactly are you trying to stop? is it a service? – BugFinder Jun 08 '18 at 06:37
  • Not service it is a .exe too. Suppose I am using C.exe and starting B.exe wihh process.start then I am starging A.exe. After A.exe started to run B.exe will be disabled. Adter A.exe stopped by user B.exe wil resume. – Turgay Öztürk Jun 08 '18 at 06:45
  • 3
    Add a [mcve] and show a minimal example of what you do and describe better what you do pretend to do. – Cleptus Jun 08 '18 at 06:52
  • Here are my codes. – Turgay Öztürk Jun 08 '18 at 07:13
  • 1
    The thing you want to do is 'suspend' the process, see https://stackoverflow.com/questions/71257/suspend-process-in-c-sharp?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – tolanj Jun 08 '18 at 09:52
  • Thanks A lot. It worked for my project. – Turgay Öztürk Jun 11 '18 at 06:04

1 Answers1

0
Process A;
    Process B;
    Process C;

    private void findExes()
    {
        List<Process> allProcesses = Process.GetProcesses().ToList().OrderBy(p => p.ProcessName).ToList();

        A = allProcesses.Find(delegate(Process pro) { return pro.ProcessName == "A"; });
        B = allProcesses.Find(delegate(Process pro) { return pro.ProcessName == "B"; });
        C = allProcesses.Find(delegate(Process pro) { return pro.ProcessName == "C"; });

    }
    private void stopAExe_Click(object sender, EventArgs e)
    { 
        findExes();

        if (A != null)
            A.Kill();

        if (  B != null)
        {
            /// RESUME B.EXE 
            /// B.EXE WİLL CONTİNUE 
        }
    }

    private void startAExe_Click(object sender, EventArgs e)
    { 
        findExes();
        if (A == null)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = @"A.exe";
            Process.Start(startInfo);

            if (B != null)
            {
                /// 
                /// DİSABLE B.EXE  ? 
            }
        }
    }

    private void startBExe_Click(object sender, EventArgs e)
    {

        findExes();

        if (  B == null)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = @"B.exe";
            Process.Start(startInfo);
        } 
    }