title: What files does that program open (on Windows)?
body: <p>I'm designing a small utility to help out with build systems.  The idea is that the utility will launch each instance of each compiler and output a log of all the files that the compiler opens during the compilation.  Something like:</p>
  
  <pre><code>track-files cc -c -o foo.o foo.c
  </code></pre>
  
  <p>Then <code>track-files</code> executes <code>cc</code> and outputs all the <code>.h</code> (and other) files that <code>cc</code> opened. But <code>cc</code> might be any compiler (or even an interpreter or just a program that does some kind of text transformation).</p>
  
  <p>A similar idea is described in <a href="http://mad-scientist.net/make/autodep.html" rel="nofollow noreferrer">Paul D Smith's Advanced Auto-Dependency tutorial</a> and attributed to Han-Wen Nienhuys.</p>
  
  <p>On Linux, FreeBSD, Solaris and HPUX I think I can use <code>LD_PRELOAD</code>.  On AIX I can use <code>LDR_PRELOAD</code> and on OSX I can use <code>DYLD_INSERT_LIBRARIES</code>.  On most of those systems I can also use <code>strace</code> if <code>LD_PRELOAD</code>-like tricks don't work.</p>
  
  <p>The one OS where I have no clue how to proceed is Windows.  I've been looking around and everything I've found so far seems, ..., unsatisfactory.</p>
  
  <p>The only answer to <a href="https://stackoverflow.com/questions/1178257/ld-preload-equivalent-for-windows-to-preload-shared-libraries">LD_PRELOAD equivalent for Windows to preload shared libraries</a> suggests AppInit_DLLs, but points out they are deprecated and/or disabled after Vista (because they were broken).</p>
  
  <p>The accepted answer on <a href="https://stackoverflow.com/questions/1210533/interposers-on-windows">interposers on Windows</a> points to Microsoft Research's <a href="http://research.microsoft.com/en-us/projects/detours/" rel="nofollow noreferrer">Detours</a> but that is proprietary (and they charge big bucks (USD10000!!!) for 64-bit support) so that would make my utility worthless for just about everyone (including me).  The other answer mentions something called WinAPI Override, but that's apparently 32-bit only.</p>
  
  <p>There's surely some dependable, non-proprietary, programmatic way to do this on Windows.  Some tracing API perhaps?  I'd be happy with support only for more recent versions of Windows (Windows 7 and 8, for example).</p>