public static void SetWeakFileAssociation(string Extension, string KeyName, string OpenWith, string FileDescription, bool Unset = false) { RegistryKey BaseKey; RegistryKey OpenMethod; RegistryKey Shell; BaseKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\" + Extension, RegistryKeyPermissionCheck.ReadWriteSubTree); if (!Unset) { BaseKey.CreateSubKey("OpenWithProgids").SetValue(KeyName, ""); OpenMethod = Registry.CurrentUser.CreateSubKey("Software\\Classes\\" + KeyName); OpenMethod.SetValue("", FileDescription); Shell = OpenMethod.CreateSubKey("Shell"); Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\""); OpenMethod.Close(); Shell.Close(); } else { RegistryKey ProgIds = BaseKey.OpenSubKey("OpenWithProgids", true); if (ProgIds != null) { ProgIds.DeleteValue(KeyName, false); } Registry.CurrentUser.OpenSubKey("Software\\Classes\\", true).DeleteSubKeyTree(KeyName, false); ProgIds.Close(); } BaseKey.Close(); // Tell explorer the file association has been changed SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero); }
internal void Write <T>(string property, T val) { var key = BaseKey.OpenSubKey(SubKeyName, true) ?? BaseKey.CreateSubKey(SubKeyName); key.SetValue(property, val); key.Close(); }
public static bool Associated(string KeyName = "ByteFlood", string Description = "TORRENT File", string Extension = ".torrent") { RegistryKey BaseKey; RegistryKey OpenMethod; RegistryKey Shell; BaseKey = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true); if (!BaseKey.GetSubKeyNames().Contains(Extension)) { return(false); } BaseKey = BaseKey.OpenSubKey(Extension); OpenMethod = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true); if (!OpenMethod.GetSubKeyNames().Contains(KeyName)) { return(false); } OpenMethod = OpenMethod.OpenSubKey(KeyName); Shell = OpenMethod.OpenSubKey("Shell"); if (!Shell.GetSubKeyNames().Contains("open")) { return(false); } BaseKey.Close(); OpenMethod.Close(); Shell.Close(); return(true); }