使用CreateProcess或system运行WSReset.exe

时间:2016-03-07 23:06:25

标签: windows winapi createprocess

我正在尝试在Windows 10上运行WSReset.exe,但一直收到文件未找到错误。 WSReset.exe肯定在“C:\ Windows \ System32 \ WSReset.exe”中,但从我的程序启动的CMD / Powershell窗口似乎无法找到它。但是在程序外部启动的CMD / Powershell窗口会执行该文件。

STARTUPINFO info = { sizeof(info) };
PROCESS_INFORMATION processInfo;
ZeroMemory(&processInfo, sizeof(processInfo));
int t = (CreateProcess(L"C:/Windows/System32/wsreset.exe", L"", NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo));
    WaitForSingleObject(processInfo.hProcess, INFINITE);
    CloseHandle(processInfo.hProcess);
    CloseHandle(processInfo.hThread);

SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = L"C:/Windows/System32/wsreset.exe";
ShExecInfo.lpParameters = L"";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);

生成“Windows无法找到...”错误消息。

1 个答案:

答案 0 :(得分:0)

该应用程序是32位。奇怪的是System32 = 64位,SysWOW64 = 32位。因此,当我调用“C:/Windows/System32/wsreset.exe”时,Windows会将其变为“C:/Windows/SysWOW64/wsreset.exe”,并且该位置没有wsreset.exe。

解决方案是在调用CreateProcess / ShellExecuteEx / System。

之前禁用重定向
//Disable redirection
PVOID OldValue = NULL;
Wow64DisableWow64FsRedirection(&OldValue);

STARTUPINFO info = { sizeof(info) };
PROCESS_INFORMATION processInfo = { 0 };
CreateProcess(L"C:/Windows/System32/WSReset.exe", L"", NULL, NULL, FALSE, 0, NULL, NULL, &info, &processInfo);
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);

//Enable redirection (important, otherwise program can crash)
Wow64RevertWow64FsRedirection(OldValue);