// string public void GetKeyValue(RegKeyType KeyType, string RegKey, string Name, out string Value) { RegistryKey pRegKey = null; switch ((int)KeyType) { case 1: pRegKey = Microsoft.Win32.Registry.CurrentUser; break; case 2: pRegKey = Microsoft.Win32.Registry.LocalMachine; break; } pRegKey = pRegKey.OpenSubKey(RegKey); if (pRegKey.GetValue(Name) != null) { Value = pRegKey.GetValue(Name).ToString(); } else { Value = "0"; // aparentemente Value não pode de jeito nenhum retornar null. } pRegKey.Close(); }
public WindowsRegistryHelper(string appName, RegKeyType keyType) { _appName = appName; _keyType = keyType; ApplicationPath = System.Reflection.Assembly.GetCallingAssembly().Location; }
public static bool GetIsLoadWithWindows(RegKeyType regType, string appName, string appPath) { Microsoft.Win32.RegistryKey key = OpenRunSubKey(regType, false); string path = (string)key.GetValue(appName); return(string.Compare(path, appPath, ignoreCase: true) == 0); }
public ConfigRegistrySettingAttribute(RegistryKey registryKey, string subKey, string keyName, Type keyType, RegKeyType regKeyType) : base(keyName, keyType) { this.RegistryKey = registryKey; this.SubKey = subKey; this.RegKeyType = regKeyType; }
public static void SetIsLoadWithWindows(RegKeyType regType, string appName, string appPath, RegKeyOp operation) { Microsoft.Win32.RegistryKey key = OpenRunSubKey(regType, true); if (operation == RegKeyOp.Update) { key.SetValue(appName, appPath); } else //remove { key.DeleteValue(appName); } }
private static Microsoft.Win32.RegistryKey OpenRunSubKey(RegKeyType regType, bool bWritable) { const string REG_KEY_MACHINE = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run"; const string REG_KEY_USER = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; if (regType == RegKeyType.LocalMachine) { return(Microsoft.Win32.Registry.LocalMachine.OpenSubKey(REG_KEY_MACHINE, bWritable)); } else { return(Microsoft.Win32.Registry.CurrentUser.OpenSubKey(REG_KEY_USER, bWritable)); } }
// int public void GetKeyValue(RegKeyType KeyType, string RegKey, string Name, out int Value) { RegistryKey pRegKey = null; switch ((int)KeyType) { case 1: pRegKey = Microsoft.Win32.Registry.CurrentUser; break; case 2: pRegKey = Microsoft.Win32.Registry.LocalMachine; break; } pRegKey = pRegKey.OpenSubKey(RegKey); Value = (int)pRegKey.GetValue(Name, null); pRegKey.Close(); }
// string internal void GetKeyValue(RegKeyType KeyType, string RegKey, string Name, out string Value) { RegistryKey oRegKey = null; switch ((int)KeyType) { case 1: oRegKey = Registry.CurrentUser; break; case 2: oRegKey = Registry.LocalMachine; break; } oRegKey = oRegKey.OpenSubKey(RegKey); Value = (string)oRegKey.GetValue(Name); oRegKey.Close(); }
/// <summary> /// Add seved file to autostart register. /// </summary> /// <param name="appName">App name in name field in register.</param> /// <param name="path">Path to file to autostart.</param> /// <param name="regKey">Switcher between CurrentUser key and LocalMachine key(administrator required). </param> /// <returns>True if register is set or false if error.</returns> public bool AddToReg(string appName, string path, RegKeyType regKey) { RegistryKey rkApp; if (regKey == RegKeyType.CurrentUser) { rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); } else if (regKey == RegKeyType.LocalMachine) { rkApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); } else { return(false); } rkApp.SetValue(appName, path); rkApp.Close(); return(true); }
// byte[] public void SetKeyValue(RegKeyType KeyType, string RegKey, string Name, byte[] Value) { RegistryKey pRegKey = null; switch ((int)KeyType) { case 1: pRegKey = Microsoft.Win32.Registry.CurrentUser; break; case 2: pRegKey = Microsoft.Win32.Registry.LocalMachine; break; } pRegKey = pRegKey.OpenSubKey(RegKey, true); System.Threading.Thread.Sleep(100); pRegKey.SetValue(Name, Value); System.Threading.Thread.Sleep(100); pRegKey.Close(); }
// byte[] internal void SetKeyValue(RegKeyType KeyType, string RegKey, string Name, byte[] Value) { RegistryKey oRegKey = null; switch ((int)KeyType) { case 1: oRegKey = Registry.CurrentUser; break; case 2: oRegKey = Registry.LocalMachine; break; } oRegKey = oRegKey.OpenSubKey(RegKey, true); oRegKey.SetValue(Name, Value); oRegKey.Close(); User32Utils.Notify_SettingChange(); WinINetUtils.Notify_OptionSettingChanges(); }
public ConfigRegistrySettingAttribute(string subKey, string keyName, Type keyType, RegKeyType regKeyType) : this(GetRegBaseKey(RegistryHive.LocalMachine), subKey, keyName, keyType, regKeyType) { }