修改注册表,双击文件直接打开
string strProject = "Exec"; string p_FileTypeName =".cdb";//文件后缀 string fileName = System.Windows.Forms.Application.ExecutablePath;// 获取启动了应用程序的可执行文件的路径及文件名 //string startPath = System.Windows.Forms.Application.StartupPath;//获取启动了应用程序的可执行文件的路径 //注册文件类型
Registry.ClassesRoot.CreateSubKey(p_FileTypeName).SetValue("", strProject, RegistryValueKind.String); using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(strProject)) { //设置图标 RegistryKey iconKey = key.CreateSubKey("DefaultIcon"); iconKey.SetValue("", System.Windows.Forms.Application.StartupPath + "\\ooopic_1564036072.ico"); //设置默认启动程序 key.CreateSubKey(@"Shell\Open\Command").SetValue("", fileName + " \"%1\"", RegistryValueKind.ExpandString); }
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步