从 system() VC++ 调用时出现 WUSA 灾难性故障 0x8000ffff

WUSA catastrophic failure 0x8000ffff when called from system() VC++

我正在尝试用 C++ 制作一个 Windows 更新卸载程序,但每当我尝试调用 wusa 时,它都会因灾难性故障 0x80000ffff 而退出。我在命令提示符中调用相同的命令,它运行良好。我该如何解决这个问题?

这是我用来调用wusa的函数:

system("wusa /uninstall /kb:2511455");

我已经想出了解决这个问题的方法,我会 post 我会为将来遇到同样问题的任何人提供我的解决方案。 system() 命令是 运行 %windir%\SysWoW64\ 中的 32 位可执行文件,而不是本机 64 位版本。为了解决这个问题,我不得不使用以下方法:

PVOID OldValue = NULL;
if( Wow64DisableWow64FsRedirection(&OldValue) ) 
{
    //  Anything in this block uses the system native files and not the WoW64 ones  
    // put native WoW64 code here
    system("wusa /uninstall /kb:2511455");
    //system("wusa /?"); // use this for testing

    //  Immediately re-enable redirection. Note that any resources
    //  associated with OldValue are cleaned up by this call.
    if ( FALSE == Wow64RevertWow64FsRedirection(OldValue) )
        {
            //  Failure to re-enable redirection should be considered
            //  a criticial failure and execution aborted.
            return 0;
        }
}