コード例 #1
0
        private void Execute(ISender client, DoStartupItemRemove message)
        {
            try
            {
                switch (message.StartupItem.Type)
                {
                case StartupType.LocalMachineRun:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.LocalMachineRunOnce:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", message.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.CurrentUserRun:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.CurrentUserRunOnce:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", message.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.StartMenu:
                    string startupItemPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), message.StartupItem.Name);

                    if (!File.Exists(startupItemPath))
                    {
                        throw new IOException("File does not exist");
                    }

                    File.Delete(startupItemPath);
                    break;
                }
            }
            catch (Exception ex)
            {
                client.Send(new SetStatus {
                    Message = $"Removing Autostart Item failed: {ex.Message}"
                });
            }
        }
コード例 #2
0
        public static void HandleDoStartupItemRemove(DoStartupItemRemove command, Client client)
        {
            try
            {
                switch (command.Type)
                {
                case 0:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name))
                    {
                        throw new Exception("Değer Kaldırılamadı");
                    }
                    break;

                case 1:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name))
                    {
                        throw new Exception("Değer Kaldırılamadı");
                    }
                    break;

                case 2:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name))
                    {
                        throw new Exception("Değer Kaldırılamadı");
                    }
                    break;

                case 3:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name))
                    {
                        throw new Exception("Değer Kaldırılamadı");
                    }
                    break;

                case 4:
                    if (!PlatformYardımcısı.A64Bitmi)
                    {
                        throw new NotSupportedException(
                                  "Bu İşlem Sadece 64 Bit İşletim Sistemlerinde Destekleniyor.");
                    }

                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name))
                    {
                        throw new Exception("Değer Kaldırılamadı");
                    }
                    break;

                case 5:
                    if (!PlatformYardımcısı.A64Bitmi)
                    {
                        throw new NotSupportedException(
                                  "Bu İşlem Sadece 64 Bit İşletim Sistemlerinde Destekleniyor.");
                    }

                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name))
                    {
                        throw new Exception("Değer Kaldırılamadı");
                    }
                    break;

                case 6:
                    var startupItemPath = Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name);

                    if (!File.Exists(startupItemPath))
                    {
                        throw new IOException("Böyle Bir Dosya Bulunmuyor.");
                    }

                    File.Delete(startupItemPath);
                    break;
                }
            }
            catch (Exception ex)
            {
                new SetStatus(string.Format("Oto-Başlangıç Öğesi Kaldırma Başarısız: {0}", ex.Message)).Execute(client);
            }
        }
コード例 #3
0
        public static void HandleDoStartupItemRemove(DoStartupItemRemove command, Networking.Client client)
        {
            try
            {
                switch (command.StartupItem.Type)
                {
                case StartupType.LocalMachineRun:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.LocalMachineRunOnce:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.CurrentUserRun:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.CurrentUserRunOnce:
                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.LocalMachineWoW64Run:
                    if (!PlatformHelper.Is64Bit)
                    {
                        throw new NotSupportedException("Only on 64-bit systems supported");
                    }

                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.LocalMachineWoW64RunOnce:
                    if (!PlatformHelper.Is64Bit)
                    {
                        throw new NotSupportedException("Only on 64-bit systems supported");
                    }

                    if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                                  "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.StartupItem.Name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case StartupType.StartMenu:
                    string startupItemPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.StartupItem.Name);

                    if (!File.Exists(startupItemPath))
                    {
                        throw new IOException("File does not exist");
                    }

                    File.Delete(startupItemPath);
                    break;
                }
            }
            catch (Exception ex)
            {
                client.Send(new SetStatus {
                    Message = $"Removing Autostart Item failed: {ex.Message}"
                });
            }
        }
コード例 #4
0
        public static void doStartupItemRemove(DoStartupItemRemove packet, ClientMosaic client)
        {
            try
            {
                switch (packet.type)
                {
                case 0:
                    if (!deleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", packet.name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case 1:
                    if (!deleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", packet.name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case 2:
                    if (!deleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", packet.name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case 3:
                    if (!deleteRegistryKeyValue(RegistryHive.CurrentUser,
                                                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", packet.name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case 4:
                    if (!is64Bit)
                    {
                        throw new NotSupportedException("Only on 64-bit systems supported");
                    }

                    if (!deleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", packet.name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case 5:
                    if (!is64Bit)
                    {
                        throw new NotSupportedException("Only on 64-bit systems supported");
                    }

                    if (!deleteRegistryKeyValue(RegistryHive.LocalMachine,
                                                "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", packet.name))
                    {
                        throw new Exception("Could not remove value");
                    }
                    break;

                case 6:
                    string startupItemPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), packet.name);

                    if (!File.Exists(startupItemPath))
                    {
                        throw new IOException("File does not exist");
                    }

                    File.Delete(startupItemPath);
                    break;
                }
            }
            catch (Exception ex)
            {
                new SetStatus(string.Format("Removing Autostart Item failed: {0}", ex.Message)).Execute(client);
            }
        }