Inheritance: SafeHandleZeroOrMinusOneIsInvalid
Esempio n. 1
0
 internal static extern int RegSetValueEx(
     SafeRegistryHandle hKey,
     String lpValueName,
     int Reserved,
     RegistryValueKind dwType,
     String lpData,
     int cbData);
 static void UnmapRegistryKey(RegistryKey registryKey)
 {
     using (var emptyHandle = new SafeRegistryHandle(IntPtr.Zero, true))
     {
         Win32Api.Registry.RedirectRegistryKey(registryKey.Handle, emptyHandle);
     }
 }
Esempio n. 3
0
 public IRegistryKey FromHandle(
     SafeRegistryHandle handle,
     RegistryView view
 )
 {
     return new RegistryKeyWrap(RegistryKey.FromHandle(handle, view));
 }
Esempio n. 4
0
 internal static extern int RegQueryValueEx(
     SafeRegistryHandle hKey,
     String lpValueName,
     int[] lpReserved,
     ref int lpType,
     [Out]StringBuilder lpData,
     ref int lpcbData);
Esempio n. 5
0
 internal unsafe static extern int RegEnumKeyEx(
     SafeRegistryHandle hKey,
     int dwIndex,
     char* lpName,
     ref int lpcbName,
     int[] lpReserved,
     [Out]StringBuilder lpClass,
     int[] lpcbClass,
     long[] lpftLastWriteTime);
Esempio n. 6
0
 internal static extern unsafe int RegEnumValue(
     SafeRegistryHandle hKey,
     int dwIndex,
     char* lpValueName,
     ref int lpcbValueName,
     IntPtr lpReserved_MustBeZero,
     int[] lpType,
     byte[] lpData,
     int[] lpcbData);
 internal static extern int RegCreateKeyEx(
     SafeRegistryHandle hKey,
     String lpSubKey,
     int Reserved,
     String lpClass,
     int dwOptions,
     int samDesired,
     ref SECURITY_ATTRIBUTES secAttrs,
     out SafeRegistryHandle hkResult,
     out int lpdwDisposition);
Esempio n. 8
0
 internal static extern int RegQueryInfoKey(
     SafeRegistryHandle hKey,
     [Out]StringBuilder lpClass,
     int[] lpcbClass,
     IntPtr lpReserved_MustBeZero,
     ref int lpcSubKeys,
     int[] lpcbMaxSubKeyLen,
     int[] lpcbMaxClassLen,
     ref int lpcValues,
     int[] lpcbMaxValueNameLen,
     int[] lpcbMaxValueLen,
     int[] lpcbSecurityDescriptor,
     int[] lpftLastWriteTime);
 private RegistryKey(SafeRegistryHandle hkey, bool writable, bool systemkey, bool remoteKey, bool isPerfData, RegistryView view)
 {
     this.hkey = hkey;
     this.keyName = "";
     this.remoteKey = remoteKey;
     this.regView = view;
     if (systemkey)
     {
         this.state |= 2;
     }
     if (writable)
     {
         this.state |= 4;
     }
     if (isPerfData)
     {
         this.state |= 8;
     }
     ValidateKeyView(view);
 }
 internal void Persist(SafeRegistryHandle hKey, string keyName)
 {
     new RegistryPermission(RegistryPermissionAccess.NoAccess, AccessControlActions.Change, keyName).Demand();
     base.WriteLock();
     try
     {
         AccessControlSections accessControlSectionsFromChanges = this.GetAccessControlSectionsFromChanges();
         if (accessControlSectionsFromChanges != AccessControlSections.None)
         {
             bool flag;
             bool flag2;
             base.Persist(hKey, accessControlSectionsFromChanges);
             base.AccessRulesModified = flag = false;
             base.AuditRulesModified = flag2 = flag;
             base.OwnerModified = base.GroupModified = flag2;
         }
     }
     finally
     {
         base.WriteUnlock();
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Creates a RegistryKey.
        /// This key is bound to hkey, if writable is <b>false</b> then no write operations
        /// will be allowed. If systemkey is set then the hkey won't be released
        /// when the object is GC'ed.
        /// The remoteKey flag when set to true indicates that we are dealing with registry entries
        /// on a remote machine and requires the program making these calls to have full trust.
        /// </summary>
        private RegistryKey(SafeRegistryHandle hkey, bool writable, bool systemkey, bool remoteKey, bool isPerfData, RegistryView view)
        {
            ValidateKeyView(view);

            _hkey = hkey;
            _keyName = "";
            _remoteKey = remoteKey;
            _regView = view;

            if (systemkey)
            {
                _state |= StateFlags.SystemKey;
            }
            if (writable)
            {
                _state |= StateFlags.WriteAccess;
            }
            if (isPerfData)
            {
                _state |= StateFlags.PerfData;
            }
        }
Esempio n. 12
0
 public static RegistryKey FromHandle(SafeRegistryHandle handle)
 {
     return FromHandle(handle, RegistryView.Default);
 }
Esempio n. 13
0
 public RegistryHandler(int hKey)
 {
     key_found = false;
     SafeRegistryHandle safeRegistryHandle = new SafeRegistryHandle(new IntPtr(hKey), true);
     root_key = RegistryKey.FromHandle(safeRegistryHandle);
 }
Esempio n. 14
0
		public RegistryKey FromHandle (SafeRegistryHandle handle)
		{
			// At this point we can't tell whether the key is writable
			// or not (nor the name), so we let the error check code handle it later, as
			// .Net seems to do.
			return new RegistryKey (handle.DangerousGetHandle (), String.Empty, true);
		}
Esempio n. 15
0
 /// <summary>
 /// Override a registry hive key to another registry key.
 /// </summary>
 /// <param name="key">Handle of the key to override.</param>
 /// <param name="newKey">Handle to override key.</param>
 internal static void RedirectRegistryKey(SafeRegistryHandle key, SafeRegistryHandle newKey)
 {
     if (0 != RegOverridePredefKey(key, newKey))
     {
         throw new Exception();
     }
 }
Esempio n. 16
0
 internal static extern int RegOpenKeyEx(IntPtr hKey, String lpSubKey,
             int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
Esempio n. 17
0
		public static RegistryKey FromHandle (SafeRegistryHandle handle)
		{
			if (handle == null)
				throw new ArgumentNullException ("handle");

			return RegistryApi.FromHandle (handle);
		}
Esempio n. 18
0
 internal static extern int RegDeleteKey(SafeRegistryHandle hKey, String lpSubKey);
Esempio n. 19
0
 internal static extern int RegDeleteKeyEx(SafeRegistryHandle hKey, String lpSubKey,
             int samDesired, int Reserved);
Esempio n. 20
0
 static extern int RegOverridePredefKey(SafeRegistryHandle key, SafeRegistryHandle newKey);
Esempio n. 21
0
 internal static extern int RegConnectRegistry(String machineName,
             SafeRegistryHandle key, out SafeRegistryHandle result);
 internal RegistrySecurity(SafeRegistryHandle hKey, string name, AccessControlSections includeSections) : base(true, ResourceType.RegistryKey, hKey, includeSections, new NativeObjectSecurity.ExceptionFromErrorCode(RegistrySecurity._HandleErrorCode), null)
 {
     new RegistryPermission(RegistryPermissionAccess.NoAccess, AccessControlActions.View, name).Demand();
 }
Esempio n. 23
0
		public RegistryKey FromHandle (SafeRegistryHandle handle)
		{
			throw new NotImplementedException ();
		}
Esempio n. 24
0
		public static RegistryKey FromHandle (SafeRegistryHandle handle, RegistryView view)
		{
			return FromHandle (handle);
		}
Esempio n. 25
0
        public static RegistryKey FromHandle(SafeRegistryHandle handle, RegistryView view)
        {
            if (handle == null) throw new ArgumentNullException(nameof(handle));
            ValidateKeyView(view);

            return new RegistryKey(handle, writable: true, view: view);
        }
Esempio n. 26
0
 internal static extern int RegDeleteValue(SafeRegistryHandle hKey, String lpValueName);
Esempio n. 27
0
 /// <summary>
 /// Creates a RegistryKey. This key is bound to hkey, if writable is <b>false</b> then no write operations will be allowed.
 /// </summary>
 private RegistryKey(SafeRegistryHandle hkey, bool writable, RegistryView view) :
     this(hkey, writable, false, false, false, view)
 {
 }
Esempio n. 28
0
 internal static extern int RegFlushKey(SafeRegistryHandle hKey);
Esempio n. 29
0
 public void Dispose()
 {
     if (_hkey != null)
     {
         if (!IsSystemKey())
         {
             try
             {
                 _hkey.Dispose();
             }
             catch (IOException)
             {
                 // we don't really care if the handle is invalid at this point
             }
             finally
             {
                 _hkey = null;
             }
         }
         else if (IsPerfDataKey())
         {
             ClosePerfDataKey();
         }
     }
 }
Esempio n. 30
0
		/// <summary>
		///	Close the current registry key and flushes the state of the registry
		/// right away.
		/// </summary>
		public void Close()
		{
			Flush ();

			// a handle to a remote hive must be closed, while one to a local
			// hive should not be closed
			if (!isRemoteRoot && IsRoot)
				return;
			
			RegistryApi.Close (this);
			handle = null;
			safe_handle = null;
		}