aaaa
aaaa

Reputation: 11

C# stop a process

I would to be able to stop a typeperf process i started in c# for remote machines. What i got so far is:

ProcessStartInfo proc = new ProcessStartInfo();

public void startLogs()
{
    for (int i = 0; i < remote_machines_num; i++)
    {
        string line = " -s " + machines[i] 
            + " -si 5 \"\\Processor(_Total)\\% Processor Time\" -o C:\\logs\\" 
            + machines[i] + ".csv";

        proc.FileName = @"C:\WINDOWS\SYSTEM32\typeperf.exe";
        proc.Arguments = line;
        Process.Start(proc);
    }
}

this really starts all monitors - but i would like to write a function that will stop monitoring and close all windows - how can i do that? thanks!

Upvotes: 1

Views: 2006

Answers (2)

Navaneethan
Navaneethan

Reputation: 2215

Are you looking for this

http://alperguc.blogspot.com/2008/11/c-process-processgetprocessesbyname.html

Upvotes: 0

Oded
Oded

Reputation: 498904

Get a reference to the started process and Kill() it.

var theRunningProc = Process.Start(proc);
theRunningProc.Kill();

Upvotes: 2

Related Questions