2016-03-07 198 views
0

我試圖在Windows 10上運行WSReset.exe,但不斷收到找不到文件的錯誤。 WSReset.exe絕對在「C:\ Windows \ System32 \ WSReset.exe」中,但從我的程序啓動的CMD/Powershell窗口似乎無法找到它。但是在我的程序外部啓動的CMD/Powershell窗口執行該文件。使用CreateProcess或系統運行WSReset.exe

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無法找到...」 錯誤消息。

回答

0

該應用程序是32位。奇怪的System32 = 64位,SysWOW64 = 32位。所以當我打電話給「C:/Windows/System32/wsreset.exe」時,窗口會將它變成「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);