0

我正在尝试将 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\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.mid\UserChoice”。

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

4

0 回答 0