public static string GetRegString( Microsoft.Win32.RegistryKey hkey, string vname ) { try { RegistryKey key = hkey.OpenSubKey( RazorRegPath ) ; if ( key == null ) { key = hkey.CreateSubKey( RazorRegPath ); if ( key == null ) return null; } string v = key.GetValue( vname ) as string; if ( v == null ) return null; return v.Trim(); } catch { return null; } }
public static void RenameSubKey(Microsoft.Win32.RegistryKey parentKey, string subKeyName, string newSubKeyName) { using (Microsoft.Win32.RegistryKey Src = parentKey.OpenSubKey(subKeyName, false)) using (Microsoft.Win32.RegistryKey Dest = parentKey.CreateSubKey(newSubKeyName)) { CopyKeyRecursive(Src, Dest); } parentKey.DeleteSubKeyTree(subKeyName); }
private static void CopyKeyRecursive(Microsoft.Win32.RegistryKey sourceKey, Microsoft.Win32.RegistryKey destKey) { foreach (string ValueName in sourceKey.GetValueNames()) { object Val = sourceKey.GetValue(ValueName); destKey.SetValue(ValueName, Val, sourceKey.GetValueKind(ValueName)); } foreach (string SubKeyName in sourceKey.GetSubKeyNames()) { using (Microsoft.Win32.RegistryKey sourceSubKey = sourceKey.OpenSubKey(SubKeyName, false)) using (Microsoft.Win32.RegistryKey destSubKey = destKey.CreateSubKey(SubKeyName)) { CopyKeyRecursive(sourceSubKey, destSubKey); } } }
private static void SetCommands(Microsoft.Win32.RegistryKey regAppAddInKey, Assembly curAssembly) { // Создание раздела Commands в переданной ветке реестра и создание записей команд в этом разделе. // Команды определяются по атрибутам переданной сборки, в которой должен быть определен атрибут класса команд // из которого получаются методы с атрибутами CommandMethod. using (regAppAddInKey = regAppAddInKey.CreateSubKey("Commands")) { var attClass = curAssembly.GetCustomAttribute<CommandClassAttribute>(); var members = attClass.Type.GetMembers(); foreach (var member in members) { if (member.MemberType == MemberTypes.Method) { var att = member.GetCustomAttribute<CommandMethodAttribute>(); if (att != null) regAppAddInKey.SetValue(att.GlobalName, att.GlobalName); } } } }