我正在制作用于执行 winmgmt 的 C# 包装类,但命令一直失败。
我尝试将StartInfo.Verb参数设置为"runas"但没有帮助。C#应用已经提升。
在提升的命令提示符下运行命令winmgmt /verifyrepository效果很好。
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));
}
当在 cmd 中运行时输出是
WMI repository is consistent
但是当使用方法运行时,VerifyRepository()我不断在同一台机器上获得此输出:
WMI repository verification failed
Error code: 0x8007007E
慕哥9229398
相关分类