亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復 winmgmt 錯誤代碼 0x8007007E?

如何修復 winmgmt 錯誤代碼 0x8007007E?

C#
撒科打諢 2023-08-13 16:29:02
我正在制作用于執行 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 failedError code:  0x8007007E
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

導致該問題的原因是應用程序在 WOW64(64 位上的 32 位)中運行,因此 winmgmt 的路徑位于 systemwow64 文件夾中,并且服務在 64 位模式下運行。通過在構建選項中取消選中“首選 32 位”來修復此問題。在不禁用首選 32 位的情況下解決此問題的另一種方法是使用 wow64apiset 在 verifyrepository 方法開始時調用Wow64DisableWow64FsRedirection,然后在最后調用Wow64RevertWow64FsRedirection函數,如下所示:

[DllImport("kernel32.dll", SetLastError = true)]

static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);


[DllImport("kernel32.dll", SetLastError = true)]

static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);


public static void VerifyRepository()

{

var wow64Value = IntPtr.Zero;

Wow64DisableWow64FsRedirection(ref wow64Value);

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();

Wow64RevertWow64FsRedirection(wow64Value);

WMIVerifyResultReceived?.Invoke(null, new WMIVerifyResultReceivedEventArgs(output));

}

請注意,如果您喜歡 32 位且未選中,則無需使用 wow64apiset 調用。


查看完整回答
反對 回復 2023-08-13
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號