I have been searching and I cannot seem to get this work. I am trying to launch SFC from a button in a C# app. I am aware that it requires rights elevation and in the scope of what I am trying to do is behavior that I want.
I have tried: To run cmd as administrator along with command? Running CMD as administrator with an argument from C# and C# how to run a process(with arguments) through an administrator elevated cmd
The code I tried last was:
private void button6_Click(object sender, EventArgs e)
{
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + "processNeedToRun")
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
Verb = "runas"
};
}
I either get no process launching at all the cmd window flashes saying incorrect credentials or the command was incorrect.
what am I doing wrong?
Per the comment added I changed it to this:
private void button6_Click(object sender, EventArgs e)
{
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + "sfc.exe /scannow")
{
RedirectStandardError = false,
RedirectStandardOutput = false,
UseShellExecute = true,
CreateNoWindow = false,
Verb = "runas"
};
}
and no change
EDIT:
So I managed to find a solution:
I created a new console app, edited the manifest to require admin and did this
Process.Start("CMD.exe", " /c SFC /Scannow");
That does have the behavior I want. Thanks for the help!