I am trying to use the chkdsk.exe
system tool found in C:\Windows\System32\chkdsk.exe
from a C# Winforms app. I want to use the System.Diagnostics.Process Class. I am using the ProcessStartInfo to set the file name to the tool and then using the args property to set my arguments.
So I have tried using System.Diagnostics.Process
with ProcessStartInfo
. But when the error occurs when the user does not have the permissions the chkdsk
window immediately closes. So I see the window in the task bar for a moment and then it closes without saying anything. I have tried both UseShellExecute=true
and false
. Also, I have tried redirecting the output stream but in a Windows app, I would have to display the output stream directly if it fails rather than a CMD window showing the error or the CHKDSK info.
using (Process CHKDSK = new Process())
{
CHKDSK.StartInfo.WorkingDirectory = @"H:\";
CHKDSK.StartInfo.FileName = "C:\\Windows\\System32\\chkdsk.exe";
CHKDSK.StartInfo.Arguments = "/r /f C:";
CHKDSK.StartInfo.UseShellExecute = true;
//CHKDSK.StartInfo.UseShellExecute = false;
CHKDSK.Start();
}
I want the CHKDSK text to be displayed in a CMD window I believe. So if the user does not have permissions the window should tell the user they do not have the permissions like it would using a CMD window and typing "call chkdsk /r /f C:"
I do not want to use start an instance of CMD and pass chkdsk
as a parameter. I want to use just the CHKDSK.exe tool