the return value is 2 and .exe does not open
The return value based on System Error Codes means ERROR_FILE_NOT_FOUND.
Yes, indeed your application failed to find the given path, because you're building it on x86
, where Windows's automatic redirection involves, and replace C:\Windows\System32
with C:\Windows\SysWOW64
, which contains 32-bit binaries for Windows.
You have two options:
Either you just build it on x64
, or disable the automatic redirection by using Wow64DisableWow64FsRedirection
as follows:
PVOID OldValue = nullptr;
Wow64DisableWow64FsRedirection(&OldValue);
ShellExecute(NULL, _T("open"), _T("C:\\Windows\\System32\\sigverif.exe"), NULL, NULL, SW_RESTORE);
Be aware that Wow64DisableWow64FsRedirection
affects globally in the current thread, as you can find more detail in the page:
Note The Wow64DisableWow64FsRedirection
function affects all file operations performed by the current thread, which can have unintended consequences if file system redirection is disabled for any length of time....
So make sure it won't affect other operations unintentionally, or set it back to enabled
immediately after your desire is resolved by invoking Wow64EnableWow64FsRedirection.