如何解决找不到可执行文件“C:\Windows\System32\Fodhelper.exe”
我正在尝试从 C++ 程序中启动上述内置 Windows 可执行文件。首先我可以确认该程序确实存在,在路径“C:\Windows\System32\fodhelper.exe”
我尝试了 3 种不同的方法来运行此程序:
System()
ShellExecuteW()
CreateProcessW()
这些方法都不起作用。我收到的错误是: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,FALSE,CREATE_NEW_CONSOLE,&startupInfo,&processinformation);
if (result == 0) {
wchar_t buf[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYstem | FORMAT_MESSAGE_IGnorE_INSERTS,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);
/* 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");
}
见下面程序的输出:
有没有人知道我在这里做错了什么?我找不到与此问题相关的任何信息。据我所知,尝试运行程序的代码是正确的,适用于不同的可执行文件。这也发生在三种不同的方法中。任何帮助将不胜感激。
解决方法
在 WOW64 上运行的 32 位应用程序将放在 file system redirection 下。因此,如果您的应用程序是 32 位应用程序,路径 "C:\\Windows\\System32\\fodhelper.exe"
将被重定向到不存在的 C:\Windows\SysWOW64\fodhelper.exe
。您有一些解决方案:
- 使用
SysNative
访问真正的system32文件夹,这意味着你需要使用类似system("C:\\Windows\\SysNative\\fodhelper.exe");
的东西 - 显式关闭文件系统重定向(一般应该避免)
- 或者更好地将您的 exe 编译为 64 位应用程序。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。