The system cannot find the path specified

前端 未结 4 1413
轮回少年
轮回少年 2020-12-19 17:24

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

F         


        
相关标签:
4条回答
  • 2020-12-19 18:05

    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".

    0 讨论(0)
  • 2020-12-19 18:14

    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");
    }
    
    0 讨论(0)
  • 2020-12-19 18:20

    Run your program in Administrator Mode.

    0 讨论(0)
  • 2020-12-19 18:27

    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.

    0 讨论(0)
提交回复
热议问题