1.文件关联要先在注册表内添加应用的相应关联类型。
代码:
RegistryKey key_step1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes", true);
string readername = "应用名" + filetype;
RegistryKey key_step2 = key_step1.CreateSubKey(readername);
RegistryKey key_step3 = key_step2.CreateSubKey("DefaultIcon");
string str1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
string str3 = str1.Substring(0, str1.LastIndexOf("\\")) + "\\sensky.ico,0";
key_step3.SetValue("", str3, RegistryValueKind.Unknown);