美文网首页
修改win注册表,指定文件(.ext)用什么程序打开,修改文件图

修改win注册表,指定文件(.ext)用什么程序打开,修改文件图

作者: RichMartin | 来源:发表于2019-07-24 10:48 被阅读0次
 WriteRegistryKey(".ext",path)

    static void WriteRegistryKey(string ext,string path)
        {
            /// 工具启动路径HKEY_CLASSES_ROOT\VREFile
            //string toolPath = @"D:\Program Files (x86)\Netdragon\VR mysticraft\VR.exe";
            string toolPath = path;
            string extension = ext;
            string fileType = "VREFile";
            string fileContent = "text/plain";
            //获取信息
            Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension);
            //删除
            //Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(extension);
            //文件注册
            registryKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension);
            registryKey.SetValue("文件类型", fileType);
            registryKey.SetValue("Content Type", fileContent);
            //设置默认图标
            Microsoft.Win32.RegistryKey iconKey = registryKey.CreateSubKey("DefaultIcon");
            iconKey.SetValue("", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\InstallCheck\\logo.ico");
            //设置默认打开程序路径
            registryKey = registryKey.CreateSubKey("shell\\open\\command");
            registryKey.SetValue("", "\"" + toolPath + "\"" + " " + "\"FilePath=%1\"");
            //关闭
            registryKey.Close();
        }

相关文章

网友评论

      本文标题:修改win注册表,指定文件(.ext)用什么程序打开,修改文件图

      本文链接:https://www.haomeiwen.com/subject/xgitrctx.html