注册表 - .sdf文件的ContextMenu扩展名

时间:2011-12-19 18:11:53

标签: c# registry

我想扩展sdf数据库文件的上下文菜单。 我现在的来源

    public static void Create()
    {
        string keyName = ".sdf";
        string contextName = "Das ist ein SDF Test";
        string exe = @"C:\Users\........exe";

        bool isWritable = true;

        try
        {
            RegistryKey classesRoot = Registry.ClassesRoot;
            RegistryKey parentKey = classesRoot.OpenSubKey(keyName, isWritable);

            parentKey.CreateSubKey("shell");

            RegistryKey shell = parentKey.OpenSubKey("shell", isWritable);
            RegistryKey context = shell.CreateSubKey(contextName);
            RegistryKey command = context.CreateSubKey("command");
            command.SetValue("", exe);
            classesRoot.Flush();
            classesRoot.Close();
        }
        catch (Exception)
        {
            throw;
        }
    }

现在,当我打开上下文菜单时,什么也没发生...... 出了什么问题?

1 个答案:

答案 0 :(得分:1)

根据你所说的,上下文菜单打开但没有任何反应,对吧?

如果是这种情况,您似乎需要将.sdf文件的完整路径传递到exe的命令行。

所以将你的exe字符串变量更新为:

string exe = @"\"C:\Users\........exe\" \"%1\"";

将传递到SDF到你的exe的完整路径。

<强>更新

再次研究之后,您实际上需要在HKCR中读取.sdk的(默认)值。在我的机器上它是“Microsoft SQL Server Compact Edition数据库文件”。因此,您需要在HKCR下方直接创建一个新子项,并将shell和命令子键放在那里。查看.txt.doc以查看示例。