【发布时间】:2019-12-14 13:20:27
【问题描述】:
我正在制作用于执行 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
【问题讨论】:
标签: c#