Я пытаюсь выполнить команду FileScan
(sfc
) через C#. Пока я запускаю sfc /scannow
в командной строке, он работает нормально.
Но через код я получаю сообщение об ошибке
Windows Защита ресурсов не может запустить службу ремонта
Вот мой код:
void RunFileScan()
{
Process p = new Process();
this.Refresh();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.Verb = "runas";
p.StartInfo.FileName = "sfc ";
p.StartInfo.Arguments = "/scannow";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
string error = p.StandardError.ReadToEnd();
string output = p.StandardOutput.ReadToEnd();
if (output.Contains("\n"))
output = Regex.Replace(output, @"\n|\0", "");
}