C#关联midi文件

时间:2016-01-05 11:18:56

标签: c# wpf associations midi associate

我试图将midi文件与我的c#应用程序关联起来 我得到以下异常,谁能告诉我为什么? 我的代码:

public static void Associate()
{
    RegistryKey FileReg = Registry.CurrentUser.CreateSubKey("Software\\Classes\\.mid");
    RegistryKey AppReg = Registry.CurrentUser.CreateSubKey("Software\\Classes\\Applications\\MyApp.exe");
    RegistryKey AppAssoc = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.mid");

    //FileReg.CreateSubKey("DefaultIcon").SetValue("", "image_path");
    FileReg.CreateSubKey("PerceivedType").SetValue("", "Bytes");

    AppReg.CreateSubKey("shell\\open\\command").SetValue("", "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" %1");
    AppReg.CreateSubKey("shell\\edit\\command").SetValue("", "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" %1");
    //AppReg.CreateSubKey("DefaultIcon").SetValue("", "image_path"); 

    AppAssoc.CreateSubKey("UserChoice").SetValue("Progid", "Applications\\MyApp.exe");

    SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
}

异常来自电话:

AppAssoc.CreateSubKey("UserChoice").SetValue("Progid", "Applications\\MyApp.exe");
  

其他信息:访问注册表项   ' HKEY_CURRENT_USER \软件\微软\的Windows \ CurrentVersion \ Explorer中\ FileExts.mid \ UserChoice'   被拒绝。

任何人都可以告诉我该做什么?

0 个答案:

没有答案