10

Can anyone shed light on why GetFile() is empty when I enumerate "C:\Windows\System32\Tasks"?

System.IO.Directory.GetFiles(@"C:\Windows\System32\Tasks");

I have checked this:

  • VS is running as Admin

  • No exception is thrown

  • There are files in root

  • I can copy files out (via explorer) to another folder and it works

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Shaun Vermaak
  • 301
  • 2
  • 13

2 Answers2

10

The problem here is that you are running the program as x86, and it's being silently redirected to another folder that has no files in it. (It will be redirected to C:\Windows\SysWOW64\Tasks)

If you compile it as x64 or AnyCPU, you should see the files.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • 1
    Explanation of the background of the redirection e.g. [here](http://serverfault.com/a/315906/54658) and [here](http://icelava.net/forums/thread/5391.aspx). – Uwe Keim Sep 02 '16 at 08:23
  • Thank you, Matthew. This was driving me mad. Don't know why I missed the "System32" part – Shaun Vermaak Sep 02 '16 at 08:26
  • @ShaunVermaak It's kindof counterintuitive, isn't it? You are running as x86, but you are redirected AWAY from a folder called `System32` to one called `SysWOW64`... wut? – Matthew Watson Sep 02 '16 at 08:36
  • @Matthew: You pointed me in the right direction. I actually removed the "prefer 32-bit" tick so now it works on both 32bit and 64bit – Shaun Vermaak Sep 02 '16 at 08:46
1

Just an assumption. Do you use any try catch blocks? This folder can have permission settings which can give you access denied error and void try catch block doesn't show you any error.