答案比我预期的要简单得多。Windows资源管理器具有自己的“打开方式”应用程序替代,并且我试图在代码的最后几行中对其进行修改。如果仅删除资源管理器替代,则文件关联将起作用。
我还告诉资源管理器,我通过调用非托管函数更改了文件关联
SHChangeNotify()
public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription){ // The stuff that was above here is basically the same // Delete the key instead of trying to change it CurrentUser = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + Extension, true); CurrentUser.DeleteSubKey("UserChoice", false); CurrentUser.Close(); // Tell explorer the file association has been changed SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);}[Dllimport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);


