注册表文件关联

 1       #region 写入程序相关
2 private void WriteApp()
3 {
4 //设置程序打开路径
5 string path = "\"C:\\Users\\Administrator\\Desktop\\Test\\TestWinForm\\bin\\Debug\\TestWinForm.exe\"";
6 RegistryKey root = Registry.ClassesRoot;
7 RegistryKey f1 = root.CreateSubKey("Form1");
8 //设置注册表程序打开的项与值,其中SetValue("", path)代表设置默认值
9 f1.CreateSubKey("shell").CreateSubKey("Open").CreateSubKey("Command").SetValue("", path);
10
11 //设置程序图标
12 string ico = "\"C:\\Users\\Administrator\\Desktop\\u7_original.ico\"";
13 f1.CreateSubKey("DefaultIcon").SetValue("", ico);
14 }
15 #endregion
16
17 #region 写关联文件
18 private void WriteRelate()
19 {
20 RegistryKey root = Registry.ClassesRoot;
21 //设置打开程序
22 root.CreateSubKey(".cws").CreateSubKey("OpenWithProgids").SetValue("Form1","");
23 }
24 #endregion

 

你可能感兴趣的:(注册表)