Could not find a part of the path 'C:\\Windows\\System32\\oobe\\info\\Backgrounds
I'm trying to list all files on Windows 7 under C:\Windows\System32\oobe\info\Backgrounds by calling the folowing:
const string logonScreenBackgroundPath = "C:\\Windows\\System32\\oobe\\info\\Backgrounds";
DirectoryInfo dInfo = new DirectoryInfo(logonScreenBackgroundPath);
string[] backgroundFiles = Directory.GetFiles(logonScreenBackgroundPath);
However I get an exception on the GetFiles call: Could not find a part of the path 'C:\Windows\System32\oobe\info\Backgrounds
I verified the folder exists and has files, I cd to it on the command prompt 开发者_如何学Cand all is well, but the c# call fails.
Calling GetFiles on C:\Windows\System32\oobe\ works fine though. Nothing different as far as folder attributes go between \oobe and \info.
After further investigation this looks like a 64-bit issue. When I build my project for "AnyCpu" the folder is found with no issues. Problem is my project has to compile for x86 and not AnyCpu due to dependencies.
SOLUTION: Looks like this is a known issue and MS has issued a hotfix for it. The problem is due to filesystem redirection.
I now disable redirection on the calling thread with the following:
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
IntPtr ptr = new IntPtr();
bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
I am pretty sure your problem is related to this article which describes what's wrong and how to fix the problem. There is a hotfix available from the site that you can install and should fix your issue. I hope this helps!
Based on the answer from Icemanind, if you're compiling a .net application, a solution that worked for us is to change your platform target (from AnyCPU) to x64.
No need to install a hotfix.
精彩评论