The system cannot find the path specified

回眸只為那壹抹淺笑 提交于 2019-12-13 12:28:54

问题


I am trying to calculate sha1 hash for some of the files from location %system%\drivers\ using C#. I know files are at the exact location but when i use

FILE.Exists("c:\\Windows\\System32\\Drivers\\1394ohci.sys") 

it always retuns false.

C:\Users\administrator>dir c:\Windows\System32\drivers\1394ohci.sys
 Volume in drive C has no label.
 Volume Serial Number is 5A4F-1E60

 Directory of c:\Windows\System32\drivers

11/21/2010  08:53 AM           229,888 1394ohci.sys
               1 File(s)        229,888 bytes
               0 Dir(s)  19,521,245,184 bytes free


C:\Users\administrator>fciv -sha1 c:\Windows\system32\drivers\1394ohci.sys
//
// File Checksum Integrity Verifier version 2.05.
//
c:\windows\system32\drivers\1394ohci.sys\*
        Error msg  : The system cannot find the path specified.
        Error code : 3

I even tried fciv.exe on the file and it also generate the same output. I tried running the command as administratror but it did not help.

I did lot of web search but nothing worked. Please help and let me know how to fix this issue.

Appreciate your help. Thank you,


回答1:


If I understand your problem correctly then you need to look at File System 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.

In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64. Access to %windir%\lastgood\system32 is redirected to %windir%\lastgood\SysWOW64. Access to %windir%\regedit.exe is redirected to %windir%\SysWOW64\regedit.exe.

Also there is small sample at the bottom of page if you can try that one

string system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32");
if(Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
{
// For 32-bit processes on 64-bit systems, %windir%\system32 folder
// can only be accessed by specifying %windir%\sysnative folder.
system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative");
}



回答2:


Run your program in Administrator Mode.




回答3:


As others have mentioned, this is the file system redirector at work. The workaround is to replace system32 with sysnative in the filepath.

This was driving me bonkers too, and it took too much work to find the simple workaround. I kept landing on pages with advanced scripting and complicated, obscure tangentially-related solutions. So I thought I'd share the "easy mode".




回答4:


From http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx:

The Exists method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.



来源:https://stackoverflow.com/questions/8775841/the-system-cannot-find-the-path-specified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!