示例#1
0
        public RegistryKeyMonitor(
            RegistryHive hive,
            string key,
            RegistryNotifyFilter filter,
            RegistryKeyWatch watch,
            KeyChangedDelegate keyChanged,
            ExceptionRaisedDelegate exceptionRaised)
        {
            if (keyChanged == null)
            {
                throw new ArgumentNullException(nameof(keyChanged));
            }

            if (exceptionRaised == null)
            {
                throw new ArgumentNullException(nameof(exceptionRaised));
            }

            RegistryHive         = hive;
            Key                  = key;
            Filter               = filter;
            WatchSubTree         = watch == RegistryKeyWatch.KeyAndSubKeys;
            this.keyChanged      = keyChanged;
            this.exceptionRaised = exceptionRaised;

            StartMonitor();
        }
示例#2
0
        public RegistryKeyMonitor(
            RegistryHive hive,
            string key,
            RegistryNotifyFilter filter,
            RegistryKeyWatch watch,
            KeyChangedDelegate keyChanged,
            ExceptionRaisedDelegate exceptionRaised)
        {
            if (keyChanged == null)
            {
                throw new ArgumentNullException(nameof(keyChanged));
            }

            if (exceptionRaised == null)
            {
                throw new ArgumentNullException(nameof(exceptionRaised));
            }

            RegistryHive = hive;
            Key = key;
            Filter = filter;
            WatchSubTree = watch == RegistryKeyWatch.KeyAndSubKeys;
            this.keyChanged = keyChanged;
            this.exceptionRaised = exceptionRaised;

            StartMonitor();
        }
示例#3
0
        public RegistryKeyWatcher(RegistryHive hive, string name, RegistryNotifyFilter notifyFilter) : this()
        {
            _baseKey = RegistryKey.OpenBaseKey(hive, RegistryView.Default);
            _key     = _baseKey.OpenSubKey(name, false);

            NotifyFilter = notifyFilter;
        }
示例#4
0
 public RegistryKeyMonitor(
     RegistryHive hive,
     string key,
     RegistryNotifyFilter filter,
     KeyChangedDelegate keyChanged,
     ExceptionRaisedDelegate exceptionRaised)
     : this(hive, key, filter, RegistryKeyWatch.KeyAndSubKeys, keyChanged, exceptionRaised)
 {
 }
示例#5
0
 public RegistryKeyMonitor(
     RegistryHive hive,
     string key,
     RegistryNotifyFilter filter,
     KeyChangedDelegate keyChanged,
     ExceptionRaisedDelegate exceptionRaised)
     : this(hive, key, filter, RegistryKeyWatch.KeyAndSubKeys, keyChanged, exceptionRaised)
 {
 }
 /// <summary>
 /// Create an observable to monitor for registry changes
 /// </summary>
 /// <param name="hKey">IntPtr</param>
 /// <param name="subKey">string</param>
 /// <param name="registrationScheduler">IScheduler</param>
 /// <param name="filter">RegistryNotifyFilter</param>
 /// <returns>IObservable</returns>
 public static IObservable <Unit> ObserveChanges(IntPtr hKey, string subKey, IScheduler registrationScheduler = null, RegistryNotifyFilter filter = RegistryNotifyFilter.ChangeLastSet)
 {
     return(Observable.Create <Unit>(
                obs =>
     {
         try
         {
             var result = Advapi32Api.RegOpenKeyEx(hKey, subKey, RegistryOpenOptions.None, RegistryKeySecurityAccessRights.Read, out var registryKey);
             if (result != 0)
             {
                 throw new Win32Exception(Marshal.GetLastWin32Error());
             }
             return new CompositeDisposable(
                 CreateKeyValuesChangedObservable(registryKey, filter).SubscribeOn(registrationScheduler ?? Scheduler.CurrentThread).Subscribe(obs),
                 Disposable.Create(() => Advapi32Api.RegCloseKey(registryKey)));
         }
         catch (Win32Exception e)
         {
             obs.OnError(e);
             return Disposable.Empty;
         }
     }));
 }
 /// <summary>
 /// Create an observable to monitor for registry changes
 /// </summary>
 /// <param name="hive">RegistryHive</param>
 /// <param name="subKey">string</param>
 /// <param name="registrationScheduler">IScheduler</param>
 /// <param name="filter">RegistryNotifyFilter</param>
 /// <returns>IObservable</returns>
 public static IObservable <Unit> ObserveChanges(RegistryHive hive, string subKey, IScheduler registrationScheduler = null, RegistryNotifyFilter filter = RegistryNotifyFilter.ChangeLastSet)
 {
     return(ObserveChanges(new IntPtr((int)hive), subKey, registrationScheduler, filter));
 }
        /// <summary>
        /// Internal method to create the value changed observable
        /// </summary>
        /// <param name="key"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private static IObservable <Unit> CreateKeyValuesChangedObservable(IntPtr key, RegistryNotifyFilter filter)
        {
            return(Observable.Create <Unit>(
                       obs =>
            {
                var eventNotify = new AutoResetEvent(false);
                var result = Advapi32Api.RegNotifyChangeKeyValue(key, true, filter, eventNotify.SafeWaitHandle.DangerousGetHandle(), true);
                if (result != 0)
                {
                    obs.OnError(new Win32Exception(Marshal.GetLastWin32Error()));
                }

                return new CompositeDisposable(
                    eventNotify,
                    SetCallbackWhenSignalled(eventNotify,
                                             () => {
                    obs.OnNext(Unit.Default);
                    obs.OnCompleted();
                }));
            }).Repeat());
        }
示例#9
0
 public static extern int RegNotifyChangeKeyValue(
     SafeRegistryHandle key,
     bool watchSubtree,
     RegistryNotifyFilter notifyFilter,
     SafeWaitHandle eventHandle,
     bool asynchronous);
示例#10
0
 public static extern int RegNotifyChangeKeyValue(IntPtr hKey, bool watchSubtree, RegistryNotifyFilter notifyFilter, IntPtr hEvent, bool asynchronous);
示例#11
0
 internal static extern int RegNotifyChangeKeyValue(SafeRegistryHandle hKey, [MarshalAs(UnmanagedType.Bool)] bool bWatchSubtree, RegistryNotifyFilter dwNotifyFilter, SafeWaitHandle hEvent, [MarshalAs(UnmanagedType.Bool)] bool fAsynchronous);
示例#12
0
 public static extern int RegNotifyChangeKeyValue(
     SafeRegistryHandle key,
     bool watchSubtree,
     RegistryNotifyFilter notifyFilter,
     SafeWaitHandle eventHandle,
     bool asynchronous);
示例#13
0
        public RegistryKeyWatcher(RegistryKey key, RegistryNotifyFilter notifyFilter) : this()
        {
            _key = key;

            NotifyFilter = notifyFilter;
        }