2011-12-19 75 views
0

我想扩展sdf数据库文件的上下文菜单。 我的电流源注册表 - .sdf文件的ContextMenu扩展

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

现在,当我打开的ContextMenu任何反应...... 什么不顺心?

+0

我需要类似的东西,并不真正了解如何解决下面的问题。你能提供工作功能吗?非常感谢 – Jerome 2012-02-13 13:08:00

回答

1

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

如果是这种情况,它看起来像你需要将.sdf文件的完整路径传递到你的exe的命令行。

所以更新您的EXE字符串变量是这样的:

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

将在完整路径SDF到你的EXE通过。

UPDATE:

再次研究后,你实际上需要阅读HKCR .sdk的(默认)值。在我的机器上它是“Microsoft SQL Server精简版数据库文件”。所以你需要在HKCR正下方创建一个新的子项,并将你的shell和命令子项放在那里。查看.txt.doc查看示例。

+0

我没有看到menuItem“Das ist ein SDF Test”。是否有权在文件扩展名.sdf下创建shell密钥? – Gepro 2011-12-19 22:15:10

+0

实际上不是,我更新以显示要做什么。 – 2011-12-20 13:20:27

+0

是的,就是这样!它工作正常,thx。 – Gepro 2011-12-21 18:19:44