void Main()
{
TraceRpt x = new TraceRpt();
x.Start();
}
//C:\\Windows\\system32\\tracerpt.exe "\Process(*)\ID Process" -f SQL -si 5 -o SQL:perfstuffDSN!log
public class TraceRpt {
public void Start() {
//Setup the Process with the ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\Windows\\system32\\typeperf.exe";
startInfo.Arguments = @"""\Process(*)\ID Process"" -f SQL -si 5 -o SQL:perfstuffDSN!log";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput=true;
startInfo.RedirectStandardError=true;
//Allows turning off flashing of cmd line:
startInfo.CreateNoWindow = true;
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
try {
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process process = Process.Start(startInfo))
{
process.WaitForExit();
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
result.Dump();
}
using (StreamReader reader = process.StandardError)
{
string result = reader.ReadToEnd();
result.Dump();
}
process.Id.Dump();
}
}
catch (System.Exception e)
{
e.Dump();
// Log error.
}
}
}