示例#1
0
 private void MoveProperty(IRegistryWrapper sourceKey, IRegistryWrapper destinationKey, string sourceProperty, string destinationProperty)
 {
     string propertyName = this.GetPropertyName(sourceProperty);
     string b = this.GetPropertyName(destinationProperty);
     try
     {
         bool flag = true;
         if (string.Equals(sourceKey.Name, destinationKey.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(propertyName, b, StringComparison.OrdinalIgnoreCase))
         {
             flag = false;
         }
         this.CopyProperty(sourceKey, destinationKey, propertyName, b, false);
         if (flag)
         {
             sourceKey.DeleteValue(propertyName);
         }
         object obj2 = destinationKey.GetValue(b);
         this.WriteWrappedPropertyObject(obj2, destinationProperty, destinationKey.Name);
     }
     catch (IOException exception)
     {
         base.WriteError(new ErrorRecord(exception, exception.GetType().FullName, ErrorCategory.WriteError, sourceKey.Name));
     }
     catch (SecurityException exception2)
     {
         base.WriteError(new ErrorRecord(exception2, exception2.GetType().FullName, ErrorCategory.PermissionDenied, sourceKey.Name));
     }
     catch (UnauthorizedAccessException exception3)
     {
         base.WriteError(new ErrorRecord(exception3, exception3.GetType().FullName, ErrorCategory.PermissionDenied, sourceKey.Name));
     }
 }
示例#2
0
        } // CopyProperty

        private void MoveProperty(
            IRegistryWrapper sourceKey,
            IRegistryWrapper destinationKey,
            string sourceProperty,
            string destinationProperty)
        {
            string realSourceProperty = GetPropertyName(sourceProperty);
            string realDestinationProperty = GetPropertyName(destinationProperty);

            try
            {
                // If sourceProperty and destinationProperty happens to be the same
                // then we shouldn't remove the property
                bool continueWithRemove = true;

                if (string.Equals(sourceKey.Name, destinationKey.Name, StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(realSourceProperty, realDestinationProperty, StringComparison.OrdinalIgnoreCase))
                {
                    continueWithRemove = false;
                }

                // Move is implemented by copying the value and then deleting the original
                // Copy property will throw an exception if it fails

                CopyProperty(
                    sourceKey,
                    destinationKey,
                    realSourceProperty,
                    realDestinationProperty,
                    false);

                // Delete sourceproperty only if it is not same as destination property
                if (continueWithRemove)
                {
                    sourceKey.DeleteValue(realSourceProperty);
                }

                object newValue = destinationKey.GetValue(realDestinationProperty);
                WriteWrappedPropertyObject(newValue, destinationProperty, destinationKey.Name);
            }
            catch (System.IO.IOException ioException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError(new ErrorRecord(ioException, ioException.GetType().FullName, ErrorCategory.WriteError, sourceKey.Name));
                return;
            }
            catch (System.Security.SecurityException securityException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError(new ErrorRecord(securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, sourceKey.Name));
                return;
            }
            catch (System.UnauthorizedAccessException unauthorizedAccessException)
            {
                // An exception occurred while trying to get the key. Write
                // out the error.

                WriteError(new ErrorRecord(unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, sourceKey.Name));
                return;
            }
        } // MoveProperty