TFS_ANTIGUO/AYA.SlnSynor/Atesa.Utilitarios/ObtieneParametros.cs

103 lines
3.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;
namespace Atesa.Utilitarios
{
public class ObtieneParametros
{
private string key = @"SOFTWARE\\Parametros";
// public ObtieneParametros(string subkey = null)
//{
// try
// {
// this.key = string.IsNullOrWhiteSpace(subkey) ? this.key : string.Format(@"{0}\{1}", this.key, subkey);
// RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);
// if (key.OpenSubKey(this.key) == null)
// {
// key.CreateSubKey(this.key, RegistryKeyPermissionCheck.ReadWriteSubTree);
// }
// }
// catch
// {
// throw new Exception("The registry key 'ParametrosProceso' does not exist and could not create it");
// }
//}
public void AddValueKeyRegedit(string KeyStringName, string KeyStringValue, bool Encrypt)
{
try
{
RegistryKey key2 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32).OpenSubKey(this.key, true);
if (key2 != null)
{
if (Encrypt)
{
//key2.SetValue(KeyStringName, new Crypt().EncryptString(KeyStringValue), RegistryValueKind.String);
}
else
{
key2.SetValue(KeyStringName, KeyStringValue, RegistryValueKind.String);
}
}
}
catch
{
}
}
public Dictionary<string, object> GetRegistrySubKeys()
{
Dictionary<string, object> dictionary = new Dictionary<string, object>();
using (RegistryKey key2 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32).OpenSubKey(this.key))
{
if (key2 == null)
{
return dictionary;
}
string[] valueNames = key2.GetValueNames();
foreach (string str in valueNames)
{
object obj2 = key2.GetValue(str);
dictionary.Add(str, obj2);
}
key2.Close();
}
return dictionary;
}
public string GetValueKeyRegedit(string KeyStringName, bool Decrypt)
{
string str = string.Empty;
try
{
RegistryKey key2 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32).OpenSubKey(this.key, false);
if (key2 == null)
{
return str;
}
if (Decrypt)
{
//str = new Crypt().DecryptString(Convert.ToString(key2.GetValue(KeyStringName)));
}
else
{
str = Convert.ToString(key2.GetValue(KeyStringName));
}
key2.Close();
}
catch
{
}
return str;
}
}
}