SetValue() 공개 정적인 메소드

public static SetValue ( string keyName, string valueName, object value ) : void
keyName string
valueName string
value object
리턴 void
예제 #1
0
        // empty string in 'valueName' means "default" value stored in key
        public static StatusCode SetValue(string keyName, string valueName, object value, RegistryValueKind valueType = RegistryValueKind.Unknown)
        {
            Logger.CallStart(keyName, valueName, value, Enum.GetName(typeof(RegistryValueKind), valueType));

            keyName = keyName.Replace("HKCU", "HKEY_CURRENT_USER")
                      .Replace("HKLM", "HKEY_LOCAL_MACHINE")
                      .Replace("HKCR", "HKEY_CLASSES_ROOT")
                      .Replace("HKU", "HKEY_USERS")
                      .Replace("HKCC", "HKEY_CURRENT_CONFIG")
                      .Replace("HKPD", "HKEY_PERFORMANCE_DATA");


            try
            {
                W32Reg.SetValue(keyName, valueName, value, valueType);
                Logger.CallSucceeded();
                return(StatusCode.Success);
            }
            catch (Exception e)
            {
                Logger.LogException(e);
                return(StatusCode.Failure);
            }
        }
예제 #2
0
 /// <summary>设置指定的注册表项的指定名称/值对。如果指定的项不存在,则创建该项。</summary>
 /// <param name="keyName">以有效注册表根(如“HKEY_CURRENT_USER”)开头的键的完整注册表路径。</param>
 /// <param name="valueName">名称/值对的名称。</param>
 /// <param name="value">要存储的值。</param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="value" /> 为 null。</exception>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="keyName" /> 未以有效注册表根开头。- 或 -<paramref name="keyName" /> 的长度超过了允许的最大长度(255 个字符)。</exception>
 /// <exception cref="T:System.UnauthorizedAccessException">
 /// <see cref="T:Microsoft.Win32.RegistryKey" /> 是只读的,因此无法对其写入;例如,它是根级节点。</exception>
 /// <exception cref="T:System.Security.SecurityException">用户没有创建或修改注册表项所需的权限。</exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
 /// </PermissionSet>
 public static void SetValue(string keyName, string valueName, object value)
 {
     Registry.SetValue(keyName, valueName, value, RegistryValueKind.Unknown);
 }