0

The following is not returning a full list of files and directories:

IEnumerable<FileSystemInfo> files = new DirectoryInfo("C:\\Windows\\System32\\drivers").EnumerateFileSystemInfos("*", SearchOption.AllDirectories);

The application is run as a administrator. There are no additional file filter drivers in place.

For example if I run:

foreach (FileSystemInfo file in files)
{
    Console.WriteLine(file.Name);
}

I get:

en-US                                             
gm.dls                                            
gmreadme.txt                                      
UMDF                                              
wimmount.sys
bfe.dll.mui                                       
ndiscap.sys.mui                                   
pacer.sys.mui                                     
qwavedrv.sys.mui                                  
scfilter.sys.mui                                  
tcpip.sys.mui 

I'm at a loss why it wouldn't be outputting all the directories and files.

Johnny Shaw
  • 157
  • 1
  • 6

1 Answers1

1

On 64-bit machines, some portions of the file system (and registry) are virtualized. It appears to me that you're running on a 64-bit machine and you are targeting x86 (or AnyCPU with the "Prefer 32-bit" setting) in your build. In 32-bit processes on 64-bit machines, C:\Windows\System32 is redirected to C:\Windows\SysWOW64. If you look at your C:\Windows\SysWOW64\drivers folder, you'll see exactly the files you are seeing in your output.

Michael Gunter
  • 12,528
  • 1
  • 24
  • 58
  • Thank you! Follow up question, is there a way to access System32 directly while maintaining x86 compatibility? Without having to build for each architecture? – Johnny Shaw May 18 '15 at 19:24
  • Off the top of my head, I don't know for .NET. Here's [an MSDN page](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187.aspx) on the concept for raw Win32. – Michael Gunter May 18 '15 at 19:26
  • Appreciate your time and help! – Johnny Shaw May 18 '15 at 19:26
  • I wanted to note that I found that C:\Windows\Sysnative will return the native System32 of the machine regardless of the architecture. – Johnny Shaw May 22 '15 at 21:09