Script for automating a large assortment of AME related actions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.9 KiB

9 months ago
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security;
  6. using System.Threading;
  7. using Ameliorated.ConsoleUtils;
  8. using Microsoft.Win32;
  9. using System.Windows.Forms;
  10. namespace amecs.Actions
  11. {
  12. public class Lockscreen
  13. {
  14. public static bool ChangeImage()
  15. {
  16. ConsoleTUI.OpenFrame.WriteCenteredLine("Select an image");
  17. Thread.Sleep(1000);
  18. var dialog = new System.Windows.Forms.OpenFileDialog();
  19. dialog.Filter = "Image Files (*.jpg; *.jpeg; *.png; *.bmp; *.jfif)| *.jpg; *.jpeg; *.png; *.bmp; *.jfif"; // Filter files by extension
  20. dialog.Multiselect = false;
  21. dialog.InitialDirectory = Globals.UserFolder;
  22. NativeWindow window = new NativeWindow();
  23. window.AssignHandle(Process.GetCurrentProcess().MainWindowHandle);
  24. if (dialog.ShowDialog(window) == DialogResult.OK)
  25. {
  26. string file;
  27. try
  28. {
  29. file = dialog.FileName;
  30. }
  31. catch (SecurityException e)
  32. {
  33. Console.WriteLine();
  34. ConsoleTUI.OpenFrame.Close("Security error: " + e.Message, ConsoleColor.Red, Console.BackgroundColor, new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "});
  35. return false;
  36. }
  37. Console.WriteLine();
  38. var choice = new ChoicePrompt() { Text = "Remove lockscreen blur? (Y/N): " }.Start();
  39. if (!choice.HasValue) return true;
  40. bool blur = choice == 0;
  41. ConsoleTUI.OpenFrame.WriteCentered("\r\nSetting lockscreen image");
  42. using (new ConsoleUtils.LoadingIndicator(true))
  43. {
  44. Thread.Sleep(500);
  45. try
  46. {
  47. if (blur)
  48. new Reg.Value()
  49. {
  50. KeyName = @"HKLM\SOFTWARE\Policies\Microsoft\Windows\System",
  51. ValueName = "DisableAcrylicBackgroundOnLogon",
  52. Type = Reg.RegistryValueType.REG_DWORD,
  53. Data = 1,
  54. }.Apply();
  55. else
  56. new Reg.Value()
  57. {
  58. KeyName = @"HKLM\SOFTWARE\Policies\Microsoft\Windows\System",
  59. ValueName = "DisableAcrylicBackgroundOnLogon",
  60. Type = Reg.RegistryValueType.REG_DWORD,
  61. Data = 0,
  62. }.Apply();
  63. } catch { }
  64. new Reg.Value()
  65. {
  66. KeyName = @"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Creative\" + Globals.UserSID,
  67. ValueName = "RotatingLockScreenEnabled",
  68. Type = Reg.RegistryValueType.REG_DWORD,
  69. Data = 0,
  70. }.Apply();
  71. new Reg.Value()
  72. {
  73. KeyName = @$"HKU\{Globals.UserSID}\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager",
  74. ValueName = "RotatingLockScreenEnabled",
  75. Type = Reg.RegistryValueType.REG_DWORD,
  76. Data = 0,
  77. }.Apply();
  78. File.Delete(Environment.ExpandEnvironmentVariables(@"%WINDIR%\Web\Screen\img100.jpg"));
  79. File.Copy(file, Environment.ExpandEnvironmentVariables(@"%WINDIR%\Web\Screen\img100.jpg"));
  80. foreach (var dataDir in Directory.EnumerateDirectories(Environment.ExpandEnvironmentVariables(@"%PROGRAMDATA%\Microsoft\Windows\SystemData")))
  81. {
  82. var subDir = Path.Combine(dataDir, "ReadOnly");
  83. if (!Directory.Exists(subDir))
  84. continue;
  85. Directory.GetDirectories(subDir, "Lockscreen_*").ToList().ForEach(x => Directory.Delete(x, true));
  86. }
  87. }
  88. Console.WriteLine();
  89. ConsoleTUI.OpenFrame.Close("Lockscreen image changed successfully", ConsoleColor.Green, Console.BackgroundColor, new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "});
  90. return true;
  91. }
  92. else
  93. {
  94. Console.WriteLine();
  95. ConsoleTUI.OpenFrame.Close("You must select an image.", new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "});
  96. return true;
  97. }
  98. }
  99. }
  100. }