How to launch SFC programatically on Windows Vista/7/8?

前端 未结 2 1228
情深已故
情深已故 2021-01-20 04:29

I\'ve been trying to solve the problem that Chris Iverson was having in this other Stackoverflow question.

I want to launch SFC (the System File

2条回答
  •  长情又很酷
    2021-01-20 05:24

    With all the help here I ended up with this and it worked fine on 8.1 x64. Thank you all very much!

        ...
        using System.Diagnostics;
        ...
    
        private void button4_Click(object sender, EventArgs e)
        {
            string docs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string snat = Environment.GetEnvironmentVariable("windir") + @"\sysnative\sfc.exe";
    
            Process a = new Process();
              a.StartInfo.FileName = snat;
              a.StartInfo.Arguments = "/SCANNOW";
              a.StartInfo.UseShellExecute = false;
              a.StartInfo.RedirectStandardOutput = true;
              a.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
              a.StartInfo.CreateNoWindow = true;
            a.Start();
    
            string output = a.StandardOutput.ReadToEnd();
            a.WaitForExit();
    
            using (StreamWriter outfile = new StreamWriter(docs + @"\Testoutput.txt"))
            {
                outfile.Write(output);
            }
    
            MessageBox.Show("DONE!");
        }
    

提交回复
热议问题