title: Windows 7 file extension association
body: <p>I am referring specifically to windows 7.</p>
  
  <p>I have code that associates a certain extension with my application as proposed by webJose on the following page:
  <a href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/630ed1d9-73f1-4cc0-bc84-04f29cffc13b" rel="noreferrer">What registry keys are responsible for file extension association?</a>
  (However i correctly write to HKEY_CURRENT_USER\Software\Classes instead of HKEY_CLASSES_ROOT as suggested)</p>
  
  <p>The above works initially, or if there are no other programs associated with the extension. However after using the Windows 7 built-in "Choose default program..." (found under the file-right-click context menu under "Open with") it re-associates the extension with whatever new program you choose.</p>
  
  <p>What happens at this point is that "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\\UserChoice" is changed by the system, and so the newly selected program takes over.</p>
  
  <p>Running the above code, to regain control over the extension will not work. The only way to regain control, is by either:</p>
  
  <ol>
  <li>Editing the UserChoice -> Progid value, which is not allowed (neither programmatically nor using regedit.exe - access denied).</li>
  <li>Or deleting the UserChoice value and making sure your application is the first in the MRUList value under \OpenWithList (this can be achieved using regedit.exe but not programmatically)</li>
  </ol>
  
  <p>My question is: Is there a way to achieve this programmatically? What registry values can be changed to regain control of an extension, after is associated with another program?</p>
  
  <p>I know it might seem obvious that if a user through explorer sets the associated application to an extension, that it would be expected to do it the same way again to re-associate the extension to a different application.</p>
  
  <p>The problem however is I have a button in my application that uses the above mentioned code to check for extension association with my application. Unfortunately with the above situation, my application displays a message confirming that the extension is already successfully associated when its not! So is there a way around this?</p>