title: Search both ProgramFiles and ProgramFiles(x86) using environment variables in C++ and C# / VB.NET
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/194157/c-sharp-how-to-get-program-files-x86-on-windows-vista-64-bit">C# - How to get Program Files (x86) on Windows Vista 64 bit</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to launch a third-party program from my own. I have done a quick search in <code>Program Files</code> and <code>Program Files (x86)</code>, and I just realized that the path returned by <code>getenv("ProgramFiles")</code> actually depends on whether I am running in x64 or Win32. </p>
  
  <p>How can I search (<strong>both in C++ and C# or VB.NET</strong>) both Program Files folders, using environment variables and not hard-coded names - since regardless of the version of my program running on the user machine, the user might have the other one installed in a different version?</p>
  
  <p>My code now: in C++:</p>
  
  <pre><code>fs::path root_directory = fs::path(getenv("ProgramFiles"));
  // and then I change to 
  root_directory = fs::path(getenv("ProgramFiles(x86)"));
  </code></pre>
  
  <p>in VB.NET:</p>
  
  <pre><code>System.Environment.GetEnvironmentVariable("ProgramFiles")
  </code></pre>
  
  <p>I looked at this source: <a href="http://msdn.microsoft.com/en-us/library/aa365743" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa365743</a> </p>
  
  <p>But if I implement what they say, I get x86 all the time...</p>