日期:2014-05-18 浏览次数:20847 次
//写入程序相关 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",""); }