Example #1
0
        private void CreateOfficeRegistryKey(StringBuilder builder, string officeKeyName, string addinProgId, string name, string description, int loadBehavior, int commandLineSafe, bool useSystemKey)
        {
            string hive      = useSystemKey ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER";
            string targetKey = String.Format(_officeRelatedKey + "\\{1}", officeKeyName, addinProgId);

            builder.AppendLine("");
            builder.AppendLine(String.Format(";--- {0} Addin ---", officeKeyName));
            builder.AppendLine(String.Format("[{0}\\{1}]", hive, targetKey));
            builder.AppendLine(String.Format("\"LoadBehavior\"=dword:{0}", RegValueConverter.ToDwordString(loadBehavior)));
            builder.AppendLine(String.Format("\"FriendlyName\"=\"{0}\"", name));
            builder.AppendLine(String.Format("\"Description\"=\"{0}\"", description));
            if (commandLineSafe > -1)
            {
                builder.AppendLine(String.Format("\"CommandLineSafe\"=dword:{0}", RegValueConverter.ToDwordString(commandLineSafe)));
            }
        }
Example #2
0
        private string ProceedExportResult(object reg)
        {
            StringBuilder result = new StringBuilder();

            bool   useSystem = Settings.Mode == SingletonSettings.RegisterMode.System;
            string rootKey   = useSystem ? "[HKEY_LOCAL_MACHINE\\" : "[HKEY_CURRENT_USER\\";

            bool        firstFlag = true;
            IEnumerable list      = reg as IEnumerable;

            if (null != list)
            {
                foreach (object item in list)
                {
                    Type itemType = item.GetType();

                    if (firstFlag)
                    {
                        firstFlag = false;
                    }
                    else
                    {
                        result.AppendLine(String.Empty);
                    }

                    string key = itemType.InvokeMember("Key",
                                                       BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
                                                       null, item, new object[0]) as string;
                    if (null != key)
                    {
                        if (key.StartsWith("\\"))
                        {
                            key = key.Substring("\\".Length);
                        }
                        result.AppendLine(String.Format("{0}{1}]", rootKey, key));
                    }

                    IEnumerable values = itemType.InvokeMember("Value",
                                                               BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
                                                               null, item, new object[0]) as IEnumerable;

                    if (values != null)
                    {
                        foreach (object value in values)
                        {
                            Type              valueType = value.GetType();
                            string            name      = valueType.InvokeMember("Name", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance, null, value, new object[0]) as string;
                            object            val       = valueType.InvokeMember("Value", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance, null, value, new object[0]);
                            RegistryValueKind kind      = (RegistryValueKind)valueType.InvokeMember("Kind", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance, null, value, new object[0]);
                            if (String.IsNullOrWhiteSpace(name))
                            {
                                name = "@";
                            }
                            else
                            {
                                name = "\"" + name + "\"";
                            }

                            switch (kind)
                            {
                            case RegistryValueKind.String:
                                result.AppendLine(String.Format("{0}=\"{1}\"", name, null != val ? val.ToString() : String.Empty));
                                break;

                            case RegistryValueKind.ExpandString:
                                result.AppendLine(String.Format("{0}={1}", name, null != val ? RegValueConverter.EncryptExpandString(val.ToString(), 13) : String.Empty));
                                break;

                            case RegistryValueKind.MultiString:
                                if (val is string[])
                                {
                                    result.AppendLine(String.Format("{0}={1}", name, null != val ? RegValueConverter.EncryptMultiString(val as string[]) : String.Empty));
                                }
                                break;

                            case RegistryValueKind.Binary:
                                if (val is byte[])
                                {
                                    result.AppendLine(String.Format("{0}={1}", name, null != val ? RegValueConverter.EncryptBinary(val as byte[]) : String.Empty));
                                }
                                break;

                            case RegistryValueKind.DWord:
                                result.AppendLine(String.Format("{0}=dword:{1}", name, RegValueConverter.ToDwordString(val)));
                                break;

                            case RegistryValueKind.QWord:
                                result.AppendLine(String.Format("{0}={1}", name, RegValueConverter.EncryptQ(Convert.ToInt64(val))));
                                break;

                            case RegistryValueKind.Unknown:
                            case RegistryValueKind.None:
                            default:
                                break;
                            }
                        }
                    }
                }
            }

            if (result.Length == 0)
            {
                return(null);
            }
            else
            {
                return(Environment.NewLine + "; --- Custom Export ---" + Environment.NewLine + result.ToString());
            }
        }