Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- using System.Diagnostics;
- using System.ComponentModel;
- using System.IO;
- namespace WpfApp1
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- string cache = @"C:\Windows\SoftwareDistribution\Download";
- ProcessStartInfo p = new ProcessStartInfo(fileName: "cmd.exe");
- public MainWindow()
- {
- InitializeComponent();
- bStart.IsEnabled = false;
- bStop.IsEnabled = false;
- bFlush.IsEnabled = false;
- System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
- dispatcherTimer.Tick += dispatcherTimer_Tick;
- dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
- dispatcherTimer.Start();
- p.CreateNoWindow = true;
- p.UseShellExecute = false;
- p.RedirectStandardOutput = true;
- }
- private void bStart_Click(object sender, RoutedEventArgs e)
- {
- p.Arguments = "/C sc config wuauserv start= auto && sc start wuauserv && sc config BITS start= auto && sc start BITS";
- Process.Start(p);
- }
- private void bStop_Click(object sender, RoutedEventArgs e)
- {
- p.Arguments = "/C sc queryex wuauserv";
- string cmdoutput = Process.Start(p).StandardOutput.ReadToEnd();
- cmdoutput = cmdoutput.Replace("\r\n", "").Replace(" ", "");
- int pFrom = cmdoutput.IndexOf("PID:") + "PID:".Length;
- int pTo = cmdoutput.LastIndexOf("FLAGS");
- String result = cmdoutput.Substring(pFrom, pTo - pFrom);
- ;
- p.Arguments = "/C sc config wuauserv start= disabled && sc stop wuauserv && sc config BITS start= disabled && sc stop BITS";
- Process.Start(p);
- p.Arguments = "/C taskkill /f /pid " + result;
- Process.Start(p);
- }
- private void bFlush_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- System.IO.Directory.Delete(cache, true);
- }
- catch
- {
- }
- }
- private void dispatcherTimer_Tick(object sender, EventArgs e)
- {
- if (!Directory.Exists(cache))
- {
- bFlush.IsEnabled = false;
- bFlush.Content = "Cache cleared";
- }
- else
- {
- bFlush.IsEnabled = true;
- bFlush.Content = "Clear cache";
- bFlush.ToolTip = "Clear windows update cache";
- }
- p.Arguments = "/C sc queryex wuauserv";
- string cmdoutput = Process.Start(p).StandardOutput.ReadToEnd();
- if (cmdoutput.Contains("STOPPED"))
- tbb.Text = "STOPPED";
- if (cmdoutput.Contains("RUNNING"))
- tbb.Text = "RUNNING";
- if (cmdoutput.Contains("STOP_PENDING"))
- tbb.Text = "STOPPING";
- switch (tbb.Text)
- {
- case "STOPPED":
- bStart.IsEnabled = true;
- bStop.IsEnabled = false;
- break;
- case "RUNNING":
- bStart.IsEnabled = false;
- bStop.IsEnabled = true;
- bFlush.IsEnabled = false;
- break;
- case "STOPPING":
- bStart.IsEnabled = false;
- bStop.IsEnabled = false;
- bFlush.IsEnabled = false;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement