/// <summary> /// Replaces the name of each environment variable embedded in the specified string with the string equivalent of the value of the variable, /// then returns the resulting string. /// Advanced feature: %LOCALAPPDATA% = Environment.SpecialFolder.LocalApplicationData /// Advanced feature: %HISTORY% = Environment.SpecialFolder.History /// Advanced feature: %INET_CACHE% = Environment.SpecialFolder.InternetCache /// Advanced feature: %SYSTEMP% = HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment|TEMP /// Advanced feature: %SYSTMP% = HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment|TMP /// </summary> public static String ExpandEnvironmentVariables(String path) { String result = path; result = Environment.ExpandEnvironmentVariables(result); result = Regex.Replace(result, "%LOCALAPPDATA%", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), RegexOptions.Compiled | RegexOptions.IgnoreCase); result = Regex.Replace(result, "%HISTORY%", Environment.GetFolderPath(Environment.SpecialFolder.History), RegexOptions.Compiled | RegexOptions.IgnoreCase); result = Regex.Replace(result, "%INET_CACHE%", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), RegexOptions.Compiled | RegexOptions.IgnoreCase); result = Regex.Replace(result, "%RECENT%", Environment.GetFolderPath(Environment.SpecialFolder.Recent), RegexOptions.Compiled | RegexOptions.IgnoreCase); result = Regex.Replace(result, "%SYSTEMP%", (String)AdvRegistry.GetValueData("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\\\TEMP", "%SYSTEMP%"), RegexOptions.Compiled | RegexOptions.IgnoreCase); result = Regex.Replace(result, "%SYSTMP%", (String)AdvRegistry.GetValueData("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\\\TMP", "%SYSTMP%"), RegexOptions.Compiled | RegexOptions.IgnoreCase); return(result); }
/// <summary>Returns value from registry. If value doen't exists returns <see cref="defaultValue"/>.</summary> public static object GetValueData(string registryPath, object defaultValue) { var AdvReg = new AdvRegistry(registryPath); var Value = AdvReg.GetValueData(); return(Value ?? defaultValue); }
/// <summary>Set value data in registry.</summary> public static void SetValueData(string valuePath, string valueData) { if (valuePath == null) { throw new ArgumentNullException("valuePath"); } if (valuePath == string.Empty) { throw new ArgumentOutOfRangeException("valuePath"); } if (valueData == null) { throw new ArgumentNullException("valueData"); } var AdvReg = new AdvRegistry(valuePath); if (!AdvReg.KeyExists) { throw new FileNotFoundException("Can't locate registry key.", AdvReg.rootKeyName + @"\" + AdvReg.subKeyPath); } // ReSharper disable PossibleNullReferenceException RootKeys[AdvReg.rootKeyName].OpenSubKey(AdvReg.subKeyPath, true).SetValue(AdvReg.valueName, valueData, RegistryValueKind.String); // ReSharper restore PossibleNullReferenceException }
public static void CreateKey(string registryPath) { var AdvReg = new AdvRegistry(registryPath); if (AdvReg.KeyExists) { throw new ArgumentException("Key already exists."); } var CreatedKey = RootKeys[AdvReg.rootKeyName].CreateSubKey(AdvReg.subKeyPath); if (CreatedKey == null) { throw new ApplicationException("Operation failed."); } }
public static RegistryKey OpenSubKey(string registryPath) { var AdvReg = new AdvRegistry(registryPath); if (AdvReg.KeyExists == false) { return(null); } if (AdvReg.subKeyPath == string.Empty) { return(RootKeys[AdvReg.rootKeyName]); } else { return(RootKeys[AdvReg.rootKeyName].OpenSubKey(AdvReg.subKeyPath)); } }
/// <summary>Returns value from registry.</summary> public static object GetValueData(string registryPath) { var AdvReg = new AdvRegistry(registryPath); return(AdvReg.GetValueData()); }
/// <summary>Determines whether the specified key exists.</summary> public static bool IsKeyExists(string registryPath) { var AdvReg = new AdvRegistry(registryPath); return(AdvReg.KeyExists); }
public static void DeleteKey(string registryPath) { var AdvReg = new AdvRegistry(registryPath); RootKeys[AdvReg.rootKeyName].DeleteSubKeyTree(AdvReg.subKeyPath); }