I'm making C# wrapper class for executing winmgmt and command keeps failing.
I tried setting the StartInfo.Verb
parameter to "runas"
but it did not help. C# application is already elevated.
Running command winmgmt /verifyrepository
in elevated command prompt works just fine.
public static void VerifyRepository()
{
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"winmgmt";
p.StartInfo.Arguments = @"/verifyrepository";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
WMIVerifyResultReceived?.Invoke(null, new WMIVerifyResultReceivedEventArgs(output));
}
When ran in cmd output is
WMI repository is consistent
but when ran using VerifyRepository()
method i keep getting this output on same machine:
WMI repository verification failed
Error code: 0x8007007E