首页 > 解决方案 > 找不到可执行文件“C:\Windows\System32\Fodhelper.exe”

问题描述

我正在尝试从 C++ 程序中启动上述内置 Windows 可执行文件。首先,我可以确认该程序确实存在,位于路径“C:\Windows\System32\fodhelper.exe”

System32 目录

我尝试了 3 种不同的方法来运行这个程序:

这些方法都不起作用。我收到的错误是:The system cannot find the file specified.

由于我可以从开始菜单、运行框和 Windows 资源管理器中将这个可执行文件作为我常用的 Windows 帐户启动,我相信我的用户帐户确实具有运行该程序的权限。此外,我没有从我的代码中收到拒绝访问错误。无论如何,我以管理员身份运行 VS,但我仍然遇到同样的问题。

我相信我用来启动该过程的代码是正确的,因为相同的代码将cmd.exe毫无问题地启动。见下文:

#include <Windows.h>
#include <tchar.h>
#include <iostream>

void CreateProcessMethod(LPCWSTR programPath) {

    HRESULT result;
    STARTUPINFO startupInfo;
    PROCESS_INFORMATION processInformation;

    ZeroMemory(&startupInfo, sizeof(startupInfo));
    startupInfo.cb = sizeof(startupInfo);
    ZeroMemory(&processInformation, sizeof(processInformation));

    result = CreateProcessW(programPath, NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &processInformation);
    if (result == 0) {

        wchar_t buf[256];
        FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            buf, (sizeof(buf) / sizeof(wchar_t)), NULL);

        /* Display error */
        std::wcout << programPath << " not started: " << buf << std::endl;

    }
    else {
        std::wcout << programPath << " started successfuly" << std::endl;
    }

}

void ShellExecuteMethod(LPCWSTR programPath) {

    SHELLEXECUTEINFOW shExecInfo = { 0 };
    shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);

        
    shExecInfo.fMask = SEE_MASK_FLAG_NO_UI;
    shExecInfo.hwnd = nullptr;
    shExecInfo.lpVerb = L"open";
    shExecInfo.lpFile = programPath;
    shExecInfo.lpParameters = L"\\C";
    shExecInfo.nShow = SW_SHOWNORMAL;

    if (ShellExecuteExW(&shExecInfo) == 0)
    {
        if (GetLastError() != ERROR_CANCELLED) // Operation canceled by the user
        {
            wchar_t buf[256];
            FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                buf, (sizeof(buf) / sizeof(wchar_t)), NULL);

            /* Display error */
            std::wcout << programPath << " not started: " << buf << std::endl;
        }
    }
    else {
        std::wcout << programPath << " started successfuly" << std::endl;
    }

}

int main(){

    CreateProcessMethod(L"C:\\Windows\\System32\\cmd.exe");
    CreateProcessMethod(L"C:\\Windows\\System32\\fodhelper.exe");

    ShellExecuteMethod(L"C:\\Windows\\System32\\cmd.exe");
    ShellExecuteMethod(L"C:\\Windows\\System32\\fodhelper.exe");

    
}

请参阅以下程序的输出:

输出窗口

有没有人知道我在这里做错了什么?我找不到与此问题相关的任何信息。据我了解,尝试运行程序的代码是正确的,适用于不同的可执行文件。这也发生在三种不同的方法中。任何帮助将不胜感激。

标签: c++redirectwow64

解决方案


在 WOW64 上运行的 32 位应用程序将被置于文件系统重定向之下。因此,如果您的应用程序是 32 位应用程序,则路径"C:\\Windows\\System32\\fodhelper.exe"将被重定向到C:\Windows\SysWOW64\fodhelper.exe不存在的路径。你有一些解决方案:

  • 用于SysNative访问真正的 system32 文件夹,这意味着您需要使用类似的东西system("C:\\Windows\\SysNative\\fodhelper.exe");
  • 显式关闭文件系统重定向(一般应避免)
  • 或者更好地将您的 exe 编译为 64 位应用程序。

推荐阅读