//Get registry value. public static string GetRegistryValue(SSRegistryMainNode RegType, string strPath, string strName, string strDefault) { string regValue; if (RegType == SSRegistryMainNode.Default) { RegType = SSRegistryMainNode.CurrentUser; } Microsoft.Win32.RegistryKey KeyRead; switch (RegType) { case SSRegistryMainNode.ClassesRoot: KeyRead = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(strPath, true); break; case SSRegistryMainNode.CurrentConfig: KeyRead = Microsoft.Win32.Registry.CurrentConfig.OpenSubKey(strPath, true); break; case SSRegistryMainNode.CurrentUser: KeyRead = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strPath, true); break; case SSRegistryMainNode.LocalMachine: KeyRead = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strPath, true); break; case SSRegistryMainNode.Users: KeyRead = Microsoft.Win32.Registry.Users.OpenSubKey(strPath, true); break; default: KeyRead = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strPath, true); break; } if (KeyRead == null) { regValue = strDefault; } else { object obj = KeyRead.GetValue(strName); if (obj == null) { regValue = strDefault; } else { regValue = obj.ToString(); } KeyRead.Close(); } return(regValue); }
// Get registry value. public static string[] GetSubKeyNames(SSRegistryMainNode RegType, string strPath) { string[] aryValue = null; if (RegType == SSRegistryMainNode.Default) { RegType = SSRegistryMainNode.CurrentUser; } Microsoft.Win32.RegistryKey KeyRead; switch (RegType) { case SSRegistryMainNode.ClassesRoot: KeyRead = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(strPath, true); break; case SSRegistryMainNode.CurrentConfig: KeyRead = Microsoft.Win32.Registry.CurrentConfig.OpenSubKey(strPath, true); break; case SSRegistryMainNode.CurrentUser: KeyRead = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strPath, true); break; case SSRegistryMainNode.LocalMachine: KeyRead = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strPath, true); break; case SSRegistryMainNode.Users: KeyRead = Microsoft.Win32.Registry.Users.OpenSubKey(strPath, true); break; default: KeyRead = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strPath, true); break; } if (KeyRead == null) { return(null); } aryValue = KeyRead.GetSubKeyNames(); KeyRead.Close(); return(aryValue); }