Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. using System;
  2. using System.Windows;
  3. using System.Diagnostics;
  4. using System.ComponentModel;
  5. using System.IO;
  6.  
  7. namespace WpfApp1
  8. {
  9. /// <summary>
  10. /// Interaction logic for MainWindow.xaml
  11. /// </summary>
  12. public partial class MainWindow : Window
  13. {
  14. string cache = @"C:\Windows\SoftwareDistribution\Download";
  15. ProcessStartInfo p = new ProcessStartInfo(fileName: "cmd.exe");
  16.  
  17. public MainWindow()
  18. {
  19. InitializeComponent();
  20. bStart.IsEnabled = false;
  21. bStop.IsEnabled = false;
  22. bFlush.IsEnabled = false;
  23. System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
  24. dispatcherTimer.Tick += dispatcherTimer_Tick;
  25. dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
  26. dispatcherTimer.Start();
  27. p.CreateNoWindow = true;
  28. p.UseShellExecute = false;
  29. p.RedirectStandardOutput = true;
  30. }
  31.  
  32. private void bStart_Click(object sender, RoutedEventArgs e)
  33. {
  34. p.Arguments = "/C sc config wuauserv start= auto && sc start wuauserv && sc config BITS start= auto && sc start BITS";
  35. Process.Start(p);
  36. }
  37.  
  38. private void bStop_Click(object sender, RoutedEventArgs e)
  39. {
  40. p.Arguments = "/C sc queryex wuauserv";
  41. string cmdoutput = Process.Start(p).StandardOutput.ReadToEnd();
  42. cmdoutput = cmdoutput.Replace("\r\n", "").Replace(" ", "");
  43. int pFrom = cmdoutput.IndexOf("PID:") + "PID:".Length;
  44. int pTo = cmdoutput.LastIndexOf("FLAGS");
  45. String result = cmdoutput.Substring(pFrom, pTo - pFrom);
  46. ;
  47. p.Arguments = "/C sc config wuauserv start= disabled && sc stop wuauserv && sc config BITS start= disabled && sc stop BITS";
  48. Process.Start(p);
  49.  
  50. p.Arguments = "/C taskkill /f /pid " + result;
  51. Process.Start(p);
  52. }
  53.  
  54.  
  55. private void bFlush_Click(object sender, RoutedEventArgs e)
  56. {
  57. try
  58. {
  59. System.IO.Directory.Delete(cache, true);
  60. }
  61. catch
  62. {
  63. }
  64.  
  65. }
  66. private void dispatcherTimer_Tick(object sender, EventArgs e)
  67. {
  68. if (!Directory.Exists(cache))
  69. {
  70. bFlush.IsEnabled = false;
  71. bFlush.Content = "Cache cleared";
  72. }
  73. else
  74. {
  75. bFlush.IsEnabled = true;
  76. bFlush.Content = "Clear cache";
  77. bFlush.ToolTip = "Clear windows update cache";
  78. }
  79.  
  80. p.Arguments = "/C sc queryex wuauserv";
  81. string cmdoutput = Process.Start(p).StandardOutput.ReadToEnd();
  82. if (cmdoutput.Contains("STOPPED"))
  83. tbb.Text = "STOPPED";
  84. if (cmdoutput.Contains("RUNNING"))
  85. tbb.Text = "RUNNING";
  86. if (cmdoutput.Contains("STOP_PENDING"))
  87. tbb.Text = "STOPPING";
  88.  
  89. switch (tbb.Text)
  90. {
  91. case "STOPPED":
  92. bStart.IsEnabled = true;
  93. bStop.IsEnabled = false;
  94. break;
  95. case "RUNNING":
  96. bStart.IsEnabled = false;
  97. bStop.IsEnabled = true;
  98. bFlush.IsEnabled = false;
  99. break;
  100. case "STOPPING":
  101. bStart.IsEnabled = false;
  102. bStop.IsEnabled = false;
  103. bFlush.IsEnabled = false;
  104. break;
  105. }
  106. }
  107.  
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement