Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Process p = new Process();
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "sfc.exe";
p.StartInfo.Arguments = " /VERIFYONLY";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
string error = p.StandardError.ReadToEnd();
string output = p.StandardOutput.ReadToEnd();

What I have tried:

I tried to get the output of sfc.exe /verifyonly and to bind that with my textbox.
But i am getting the output as null. And some text is comming as "\n\0\n\0\n\0M\0i\0c\0r\0o\0s\0o\0f\0t\0 \0(\0R\0)\0 \0W\"
this is the rela output with \n,\0 and spaces added into it.
Unable to see this in TextVisualizer as well.
Posted
Updated 28-Jan-20 5:16am
Comments
ZurdoDev 28-Jan-20 8:26am    
So, sometimes you do get data?

I don't quite understand.
Richard MacCutchan 28-Jan-20 9:58am    
Most likely because sfc requires administrator privileges to run.

1 solution

First, SFC required admin permissions to run, so if you're not running your code as an admin, SFC isn't going to work either.

Next, you execute the SFC command with a call to .Start, but then the very next line you call .ReadToEnd, which DOES NOT WAIT FOR THE PROCESS YOU LAUNCHED TO COMPLETE! .ReadToEnd will only return what was written to the stream AT THAT TIME. If there wasn't anything written to the console by the app, ReadToEnd is only going to return what was written to that point. ReadToEnd does NOT wait for the process you launched to complete before returning the stream content.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900