static void Register(string filePath)
{
if (!File.Exists(filePath)) Console.Out.WriteLine("parameter error");
using (RegistryKey root = Registry.ClassesRoot)
{
string fileName = Path.GetFileNameWithoutExtension(filePath);
using (RegistryKey register = root.CreateSubKey(@"*" + fileName))
{
register.SetValue("icon", filePath);
register.SetValue(null, fileName);//默认值修改
}
using (RegistryKey register = root.CreateSubKey(@"*" + fileName + @"\command"))
register.SetValue(null, "\"" + filePath + "\" \"%1\"");
}
}
管理权限启动程序,否则注册表的修改无效
Registry.ClassesRoot下
参考:https://blog.csdn.net/CrowNAir/article/details/78128566 http://www.winwin7.com/JC/14477.html