Registry - ContextMenu extension of .sdf files

爷,独闯天下 提交于 2020-01-14 05:38:05

问题


i want to extend the contextmenu of sdf database-files. my current source

    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;
        }
    }

now, when i opened the contextmenu nothing is happened... what goes wrong?


回答1:


Based on what you've said, the context menu opens but nothing happens, right?

If this is the case, it looks like you need to pass the full path of the .sdf file into your exe's command line.

So update your exe string variable to be this:

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

which will pass in the full path to the SDF to your exe.

UPDATE:

After researching again, you actually need to read the (default) value of .sdk in HKCR. On my machine it's "Microsoft SQL Server Compact Edition Database File". So you would need to create a new subkey directly below HKCR and and put your shell and command subkeys in there. Check out .txt and .doc to see an example.



来源:https://stackoverflow.com/questions/8565521/registry-contextmenu-extension-of-sdf-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!