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();
}
网友评论