The system cannot find the path specified: Demystified

Have you ever tried running some cryptographic hash calculator on some of the existing system files? Or even tried reading them programmatically and it failed with below error?

       Error msg  : The system cannot find the path specified.

Guess what, I had a similar issue last weekend.  I knew file existed at the location and I could open it in notepad++ but fciv.exe was saying, “file not found”.

Even File.Exists(@”c:\windows\system32\drivers\1394ohci.sys”) returned false. I searched web multiple times and even asked couple of my friends who also did not have any clue. I found multiple users asking about the same question over and over but the answer seemed un-gettable.

Finally, I asked the question on stackoverflow.com forum and one of the experts commented by asking if I was running 32-bit application on 64-bit machine? That’s when I realized the whole mess up was because of File System Redirection.

Why FS Redirector?

The %windir%\System32 directory is reserved for 64-bit applications. Most DLL file names were not changed when 64-bit versions of the DLLs were created, so 32-bit versions of the DLLs are stored in a different directory. WOW64 hides this difference using a file system redirector.

Can I disable it?

Oh yeah, of course you can disable it. Microsoft has provided couple of APIs which can be used to disable FS redirection for the current thread/process.

As I was working on C# application, I will show you how it can be done in a managed code. First thing first, declare the signature for the APIs.

1
2
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
1
2
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

Then, call it just before accessing the system files.

1
2
3
IntPtr ptr = new IntPtr();
bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
File.Exists(@"c:\windows\system32\drivers\1394ohci.sys")

Once, you are done with the file access, enable the redirection using below API.

1
bool isWow64FsRedirectionReverted = Wow64RevertWow64FsRedirection(ptr);

Please refer to the below links for more information about the APIs and FS redirector. I hope this small post will be helpful to many of us trying to uncover the same mystery.

Further reading:

Rating 3.00 out of 5

2 Responses to “The system cannot find the path specified: Demystified”

  1. Ajeet Says:

    Nice read…. I am sure it will help a lot of people who are having this problem..One more beer for you Abhie…

  2. vikas Says:

    good one… though i am not .net developer but I like your readings… hope one more good reading very soon :-)

Leave a Reply

This entry was posted on Monday, January 9th, 2012 at 10:47 am and is filed under HOWTO's. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes