写了一个程序,想在每当右键点击txt文件时,在右键上显示"使用txtReader打开",点击后调用程序打开文件,如何设置注册表?

解决方案 »

  1.   

    看这里,C#操作注册表:
    需要了解一下,启动程序的原理,给点代码,应该差不多了。using Micorsoft.Win32;        RegistryKey shell = Registry.ClassesRoot.OpenSubKey(@".txt\shell", true);
            RegistryKey custom = shell.CreateSubKey("使用txtReader打开");
            RegistryKey cmd = custom.CreateSubKey("command");
            cmd.SetValue("", Application.ExecutablePath + " %1");
            //Application.ExecutablePath 是本程序自身的路径
            //%1 是传入打开的文件路径
            cmd.Close();
            custom.Close();
            shell.Close();这样可以实现单击该菜单启动你的程序。但是如果想打开,就必须在你程序中写代码了,修改Main方法,加入参数才行。
      

  2.   

    当运行到第二行(RegistryKey custom )时显示“未将对象引用设置到对象的实例”,不知道怎么回事。