public static bool RemoveFromStartup() { if (WindowsAccountHelper.GetAccountType() == "Admin") { //try //{ // ProcessStartInfo startInfo = new ProcessStartInfo("schtasks") // { // Arguments = "/delete /tn \"" + Settings.STARTUPKEY + "\" /f", // UseShellExecute = false, // CreateNoWindow = true // }; // Process p = Process.Start(startInfo); // p.WaitForExit(1000); // if (p.ExitCode == 0) return true; //} //catch (Exception) //{ //} return(RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY)); } else { return(RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY)); } }
public static bool RemoveFromStartup() { if (WindowsAccountHelper.GetAccountType() == "Admin") { try { ProcessStartInfo startInfo = new ProcessStartInfo("schtasks") { Arguments = "/delete /tn \"" + Settings.STARTUPKEY + "\" /f", UseShellExecute = false, CreateNoWindow = true }; Process p = Process.Start(startInfo); p.WaitForExit(1000); if (p.ExitCode == 0) { return(true); } } catch (Exception) { } return(RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY)); } else { return(RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY)); } }
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}" }); } }
public static bool RemoveFromStartup() { if (WindowsAccountHelper.GetAccountType() == "Admin") { bool success = RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY); if (success) { return(true); } return(RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY)); } else { return(RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY)); } }
public void RemoveFromStartup(string startupName) { if (UserAccount.Type == AccountType.Admin) { ProcessStartInfo startInfo = new ProcessStartInfo("schtasks") { Arguments = "/delete /tn \"" + startupName + "\" /f", UseShellExecute = false, CreateNoWindow = true }; Process p = Process.Start(startInfo); p.WaitForExit(1000); if (p.ExitCode == 0) { return; } } RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName); }
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); } }
public static void HandleDoStartupItemRemove(Packets.ServerPackets.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("Could not remove value"); } break; case 1: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name)) { throw new Exception("Could not remove value"); } break; case 2: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name)) { throw new Exception("Could not remove value"); } break; case 3: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name)) { throw new Exception("Could not remove value"); } break; case 4: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name)) { throw new Exception("Could not remove value"); } break; case 5: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name)) { throw new Exception("Could not remove value"); } break; case 6: string startupItemPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name); if (!File.Exists(startupItemPath)) { throw new IOException("File does not exist"); } File.Delete(startupItemPath); break; } } catch (Exception ex) { new Packets.ClientPackets.SetStatus(string.Format("Removing Autostart Item failed: {0}", ex.Message)).Execute(client); } }
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}" }); } }
public void HandleDoStartupItemRemove(TcpSocketSaeaSession session) { try { var pack = GetMessageEntity <StartupItemsPack>(session); foreach (var command in pack.StartupItems) { switch (command.Type) { case StartupType.LocalMachineRun: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name)) { throw new Exception("Could not remove value"); } break; case StartupType.LocalMachineRunOnce: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name)) { throw new Exception("Could not remove value"); } break; case StartupType.CurrentUserRun: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name)) { throw new Exception("Could not remove value"); } break; case StartupType.CurrentUserRunOnce: if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.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.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.Name)) { throw new Exception("Could not remove value"); } break; case StartupType.StartMenu: string startupItemPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name); if (!File.Exists(startupItemPath)) { throw new IOException("File does not exist"); } File.Delete(startupItemPath); break; } } this.HandleGetStartupItems(session); } catch (Exception ex) { SendTo(CurrentSession, MessageHead.C_STARTUP_OPER_RESPONSE, new StartupOperResponsePack() { OperFlag = OperFlag.RemoveStartupItem, Successed = false, Msg = ex.Message }); } }