日期:2014-05-18  浏览次数:20739 次

如何让我的程序在安装之后直接关联指定格式的文件,并为该类文件指定一个图标
我的目的:双击安装包,安装完毕,桌面上的.cws文件变成我指定的图标,并且双击能用我的程序打开该文件。
求各位帮忙!分少,见谅。谢谢啦!

------解决方案--------------------
修改注册表关联程序
http://topic.csdn.net/t/20041001/11/3422823.html
------解决方案--------------------
C# code

//写入程序相关
        private void WriteApp()
        {
            //设置程序打开路径
            string path = "\"C:\\Users\\Administrator\\Desktop\\Test\\TestWinForm\\bin\\Debug\\TestWinForm.exe\"";
            RegistryKey root = Registry.ClassesRoot;
            RegistryKey f1 = root.CreateSubKey("Form1");
            //设置注册表程序打开的项与值,其中SetValue("", path)代表设置默认值
            f1.CreateSubKey("shell").CreateSubKey("Open").CreateSubKey("Command").SetValue("", path);

            //设置程序图标
            string ico = "\"C:\\Users\\Administrator\\Desktop\\u7_original.ico\"";
            f1.CreateSubKey("DefaultIcon").SetValue("", ico);
        }

        //写关联文件
        private void WriteRelate()
        {
            RegistryKey root = Registry.ClassesRoot;
            //设置打开程序
            root.CreateSubKey(".cws").CreateSubKey("OpenWithProgids").SetValue("Form1","");
        }