title: How can 32-bit application find the location of 64-bit Program Files directory on Windows Vista 64-bit?
body: <p>I'm struggling with a problem of how to determine the location of the 64-bit Program Files directory on 64-bit Windows Vista from a 32-bit application.</p>
  <p>Calls to <code>SHGetKnownFolderPath(FOLDERID_ProgramFilesX64)</code> do not return anything. The <a href="http://en.wikipedia.org/wiki/Microsoft_Developer_Network" rel="noreferrer">MSDN</a> article <em><a href="http://msdn.microsoft.com/en-us/library/bb762584%28VS.85%29.aspx" rel="noreferrer">KNOWNFOLDERID</a></em> also states that this particular call with <code>FOLDERID_ProgramFilesX64</code> is not supported for a 32-bit application.</p>
  <p>I would like to avoid as much as possible hardcoding the path to &quot;C:\Program Files&quot;.
  Doing something like <code>GetWindowsDirectory()</code>, extracting the drive from the return value and adding &quot;\Program Files&quot; to it is not appealing either.</p>
  <p>How can a 32-bit application properly get the location of the folder from 64-bit Windows Vista?</p>
  <h3>Background</h3>
  <p>Our application has a service component which is supposed to launch other processes based on requests from user-session-specific component. The applications launched can be 32-bit or 64-bit. We do this is via <code>CreateProcessAsUser()</code> by passing in a token from initiating user-session process. For call to <code>CreateProcessAsUser</code>, we create an environment block via the <code>CreateEnvironmentBlock()</code> API. The problem is that <code>CreateEnvironmentBlock()</code>, using the token of the user-session application, creates a block with ProgramW6432=&quot;C:\Program Files (x86)&quot;, which is a problem for 64-bit applications. We need to override it with the proper value.</p>