Exemplo n.º 1
0
            /// <summary>
            /// レジストリに登録
            /// </summary>
            /// <param name="startup_register_place">スタートアップの登録場所</param>
            /// <param name="register_name">登録名</param>
            /// <param name="file_path">ファイルパス</param>
            /// <param name="parameter">パラメータ</param>
            private static void RegisterRegistry(
                StartupRegisterPlace startup_register_place,
                string register_name,
                string file_path,
                string parameter
                )
            {
                RegistryHivePath registry_hive_path = null;

                switch (startup_register_place)
                {
                case StartupRegisterPlace.RegistryLogonUser:
                    registry_hive_path = StartupRegistryHidePath.LogonUser();
                    break;

                case StartupRegisterPlace.RegistryAllUser:
                    registry_hive_path = StartupRegistryHidePath.AllUser();
                    break;

                case StartupRegisterPlace.RegistryLogonUserOnce:
                    registry_hive_path = StartupRegistryHidePath.LogonUserOnce();
                    break;

                case StartupRegisterPlace.RegistryAllUserOnce:
                    registry_hive_path = StartupRegistryHidePath.AllUserOnce();
                    break;

                case StartupRegisterPlace.RegistryAllUser32Bit:
                    registry_hive_path = StartupRegistryHidePath.AllUser32Bit();
                    break;

                case StartupRegisterPlace.RegistryAllUserOnce32Bit:
                    registry_hive_path = StartupRegistryHidePath.AllUserOnce32Bit();
                    break;
                }

                string write_string;     // 書き込む文字列

                if (string.IsNullOrEmpty(parameter))
                {
                    write_string = file_path;
                }
                else
                {
                    write_string = "\"" + file_path + "\" " + parameter;
                }

                using (Microsoft.Win32.RegistryKey base_registry_key = Microsoft.Win32.RegistryKey.OpenBaseKey(registry_hive_path.RegistryHive, Microsoft.Win32.RegistryView.Default))
                {
                    using (Microsoft.Win32.RegistryKey sub_registry_key = base_registry_key.CreateSubKey(registry_hive_path.Path))
                    {
                        sub_registry_key.SetValue(register_name, write_string, Microsoft.Win32.RegistryValueKind.String);
                    }
                }
            }
Exemplo n.º 2
0
            /// <summary>
            /// 指定した登録場所でキャンセルされているスタートアップを取得
            /// </summary>
            /// <param name="startup_information">スタートアップ情報</param>
            /// <param name="register_place">登録場所</param>
            /// <param name="registry_hive_path">RegistryHivePath</param>
            private static void GetDesignationCancelStartup(
                ref System.Collections.Generic.List <StartupInformation> startup_information,
                StartupRegisterPlace register_place,
                RegistryHivePath registry_hive_path
                )
            {
                try
                {
                    using (Microsoft.Win32.RegistryKey base_registry_key = Microsoft.Win32.RegistryKey.OpenBaseKey(registry_hive_path.RegistryHive, Microsoft.Win32.RegistryView.Default))
                    {
                        using (Microsoft.Win32.RegistryKey sub_registry_key = base_registry_key.OpenSubKey(registry_hive_path.Path))
                        {
                            foreach (string value_name in sub_registry_key.GetValueNames())
                            {
                                try
                                {
                                    byte[] key_value = (byte[])sub_registry_key.GetValue(value_name);        // 値

                                    if (key_value.Length != 0)
                                    {
                                        if ((key_value[0] % 2) != 0)
                                        {
                                            foreach (StartupInformation si in startup_information)
                                            {
                                                string extension = "";        // 拡張子

                                                switch (si.RegisterPlace)
                                                {
                                                case StartupRegisterPlace.FolderLogonUser:
                                                case StartupRegisterPlace.FolderAllUser:
                                                    extension = ".lnk";
                                                    break;
                                                }
                                                if ((value_name.ToLower() == (si.RegisterName + extension).ToLower()) && (register_place == si.RegisterPlace))
                                                {
                                                    si.RegisterState = false;
                                                }
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
Exemplo n.º 3
0
            /// <summary>
            /// スタートアップの有効状態を変更
            /// </summary>
            /// <param name="startup_register_place">スタートアップの登録場所</param>
            /// <param name="register_name">登録名</param>
            /// <param name="effective_state">有効状態</param>
            /// <exception cref="FreeEcho.FEStartupControl.ChangeEffectiveStateStartupException"></exception>
            public static void ChangeEffectiveState(
                StartupRegisterPlace startup_register_place,
                string register_name,
                bool effective_state
                )
            {
                try
                {
                    RegistryHivePath registry_hive_path = null;
                    string           extension          = null; // 拡張子

                    switch (startup_register_place)
                    {
                    case StartupRegisterPlace.FolderLogonUser:
                        registry_hive_path = StartupRegistryHidePath.DisabledFolderLogonUser();
                        extension          = ".lnk";
                        break;

                    case StartupRegisterPlace.FolderAllUser:
                        registry_hive_path = StartupRegistryHidePath.DisabledFolderAllUser();
                        extension          = ".lnk";
                        break;

                    case StartupRegisterPlace.RegistryLogonUser:
                        registry_hive_path = StartupRegistryHidePath.DisabledRegistryLogonUser();
                        break;

                    case StartupRegisterPlace.RegistryAllUser:
                        registry_hive_path = StartupRegistryHidePath.DisabledRegistryAllUser();
                        break;

                    case StartupRegisterPlace.RegistryAllUser32Bit:
                        registry_hive_path = StartupRegistryHidePath.DisabledRegistryAllUser32Bit();
                        break;
                    }

                    using (Microsoft.Win32.RegistryKey base_registry_key = Microsoft.Win32.RegistryKey.OpenBaseKey(registry_hive_path.RegistryHive, Microsoft.Win32.RegistryView.Default))
                    {
                        using (Microsoft.Win32.RegistryKey sub_registry_key = base_registry_key.CreateSubKey(registry_hive_path.Path))
                        {
                            sub_registry_key.SetValue(register_name + extension, effective_state ? new byte[] { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } : new byte[] { 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, Microsoft.Win32.RegistryValueKind.Binary);
                        }
                    }
                }
                catch
                {
                    throw new ChangeEffectiveStateStartupException();
                }
            }
Exemplo n.º 4
0
            /// <summary>
            /// 指定したレジストリに登録されているスタートアップを取得
            /// </summary>
            /// <param name="startup_information">スタートアップ情報</param>
            /// <param name="startup_register_place">登録場所</param>
            /// <param name="registry_hive_path">RegistryHivePath</param>
            private static void GetDesignationRegistry(
                ref System.Collections.Generic.List <StartupInformation> startup_information,
                StartupRegisterPlace startup_register_place,
                RegistryHivePath registry_hive_path
                )
            {
                try
                {
                    using (Microsoft.Win32.RegistryKey base_registry_key = Microsoft.Win32.RegistryKey.OpenBaseKey(registry_hive_path.RegistryHive, Microsoft.Win32.RegistryView.Default))
                    {
                        using (Microsoft.Win32.RegistryKey sub_registry_key = base_registry_key.OpenSubKey(registry_hive_path.Path))
                        {
                            string[] value_name = sub_registry_key.GetValueNames();       // 名前

                            for (int count = 0; count < value_name.Length; count++)
                            {
                                try
                                {
                                    string key_value = (string)sub_registry_key.GetValue(value_name[count]);      // 値

                                    if (key_value.Length != 0)
                                    {
                                        string path;        // パス
                                        string parameter;   // パラメータ

                                        SeparateFullPathParameter(key_value, out path, out parameter);
                                        StartupInformation new_startup_information = new StartupInformation
                                        {
                                            RegisterName  = value_name[count],
                                            Path          = path,
                                            Parameter     = parameter,
                                            RegisterPlace = startup_register_place
                                        };
                                        startup_information.Add(new_startup_information);
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
Exemplo n.º 5
0
            /// <summary>
            /// スタートアップを削除
            /// </summary>
            /// <param name="startup_register_place">登録場所</param>
            /// <param name="register_name">登録名</param>
            /// <exception cref="FreeEcho.FEStartupControl.DeleteStartupException"></exception>
            public static void DeleteStartup(
                StartupRegisterPlace startup_register_place,
                string register_name
                )
            {
                try
                {
                    string           startup_folder_path = null;
                    RegistryHivePath registry_hive_path  = null;

                    switch (startup_register_place)
                    {
                    case StartupRegisterPlace.FolderLogonUser:
                        startup_folder_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
                        break;

                    case StartupRegisterPlace.FolderAllUser:
                        startup_folder_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonStartup);
                        break;

                    case StartupRegisterPlace.RegistryLogonUser:
                        registry_hive_path = StartupRegistryHidePath.LogonUser();
                        break;

                    case StartupRegisterPlace.RegistryAllUser:
                        registry_hive_path = StartupRegistryHidePath.AllUser();
                        break;

                    case StartupRegisterPlace.RegistryLogonUserOnce:
                        registry_hive_path = StartupRegistryHidePath.LogonUserOnce();
                        break;

                    case StartupRegisterPlace.RegistryAllUserOnce:
                        registry_hive_path = StartupRegistryHidePath.AllUserOnce();
                        break;

                    case StartupRegisterPlace.RegistryAllUser32Bit:
                        registry_hive_path = StartupRegistryHidePath.AllUser32Bit();
                        break;

                    case StartupRegisterPlace.RegistryAllUserOnce32Bit:
                        registry_hive_path = StartupRegistryHidePath.AllUserOnce32Bit();
                        break;
                    }

                    if (startup_folder_path != null)
                    {
                        startup_folder_path += "/" + register_name + ".lnk";
                        System.IO.File.Delete(startup_folder_path);
                    }
                    else if (registry_hive_path != null)
                    {
                        using (Microsoft.Win32.RegistryKey base_registry_key = Microsoft.Win32.RegistryKey.OpenBaseKey(registry_hive_path.RegistryHive, Microsoft.Win32.RegistryView.Default))
                        {
                            using (Microsoft.Win32.RegistryKey sub_registry_key = base_registry_key.CreateSubKey(registry_hive_path.Path))
                            {
                                sub_registry_key.DeleteValue(register_name);
                            }
                        }
                    }
                }
                catch
                {
                    throw new DeleteStartupException();
                }
            }