Question

The win32 API SearchPath API fails to find the "telnet.exe" binary path even though its present in system32.

However when I did a search for notepad.exe, with the same code it returns the file path. What puzzles me here is that both notepad.exe and telnet.exe lies in the same directory i.e C:\windows\system32.

This is the code I have written

char path[MAX_PATH] = {0};
LPSTR* ptr = NULL;

DWORD dwRet = SearchPathA(NULL, "telnet.exe",
    NULL, MAX_PATH, (LPSTR)path, ptr);

This would always return 0 and the GetLastError is 2 ( File not found)

Any idea what is happening here?

I am using windows 2008 R2 enterprise edition on an x64 machine

Thanks & Regards Sunil

Was it helpful?

Solution

It's not working because you application is 32 bit and is being affected by the File System Redirector. Your application is not looking in C:\Windows\System32 but is instead being redirected to C:\Windows\SysWow64.

notepad.exe exists in both System32 and SysWow64, but telnet.exe only exists in System32. So you application does not find it when it searches the path.

You can disable this behavior for your application by calling Wow64DisasbleWow64FsRedirection. But note the warnings in the documentation links that indicate that this should only be disabled temporarily and then re-enabled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top