Exemplo n.º 1
0
        public static void WriteUpdateList()
        {
            var wuaSession  = new UpdateSessionClass();
            var wuaSearcher = wuaSession.CreateUpdateSearcher();
            var wuaSearch   = wuaSearcher.Search("IsInstalled=1 and IsPresent=1 and Type='Software'");
            var updates     = wuaSearch.Updates.OfType <IUpdate>().ToList();

            foreach (var update in updates)
            {
                var id = update.Identity;

                var result = HelperTools.KeyValueListToConsoleOutput(new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(nameof(id.UpdateID), id.UpdateID),
                    new KeyValuePair <string, object>(nameof(id.RevisionNumber), id.RevisionNumber),

                    new KeyValuePair <string, object>(nameof(update.Title), update.Title),
                    new KeyValuePair <string, object>(nameof(update.IsUninstallable), update.IsUninstallable),

                    new KeyValuePair <string, object>(nameof(update.SupportUrl), update.SupportUrl),

                    new KeyValuePair <string, object>(nameof(update.MinDownloadSize), update.MinDownloadSize),
                    new KeyValuePair <string, object>(nameof(update.MaxDownloadSize), update.MaxDownloadSize),
                    new KeyValuePair <string, object>(nameof(update.LastDeploymentChangeTime), update.LastDeploymentChangeTime)
                });

                Console.WriteLine(result);
            }
        }
Exemplo n.º 2
0
        public static void UninstallUpdate(string updateId)
        {
            Console.WriteLine("Scanning updates...");
            var wuaSession  = new UpdateSessionClass();
            var wuaSearcher = wuaSession.CreateUpdateSearcher();
            var wuaSearch   =
                wuaSearcher.Search($"Type='Software' and IsInstalled=1 and UpdateID='{updateId}' and IsPresent=1");
            var updates = wuaSearch.Updates.OfType <IUpdate>().ToList();

            if (!updates.Any())
            {
                throw new ArgumentException("Selected update was not found");
            }
            var uninstallable = updates.Where(x => x.IsUninstallable).ToList();

            if (!uninstallable.Any())
            {
                throw new ArgumentException("Selected update is not uninstallable");
            }

            var wuaInstaller = wuaSession.CreateUpdateInstaller();

            wuaInstaller.Updates = new UpdateCollectionClass();
            foreach (var update in uninstallable)
            {
                wuaInstaller.Updates.Add(update);
            }

            Console.WriteLine("Uninstalling " + string.Join("; ", uninstallable.Select(x => x.Title)) + "...");
            WaitForInstallerBusy(wuaInstaller);
            var result = wuaInstaller.Uninstall();

            WaitForInstallerBusy(wuaInstaller);

            switch (result.ResultCode)
            {
            case OperationResultCode.orcNotStarted:
                throw new ArgumentException("Selected update is not uninstallable");

            case OperationResultCode.orcInProgress:
                break;

            case OperationResultCode.orcSucceeded:
                break;

            case OperationResultCode.orcSucceededWithErrors:
                break;

            case OperationResultCode.orcFailed:
                throw new COMException("Selected update is not uninstallable", result.HResult);

            case OperationResultCode.orcAborted:
                throw new OperationCanceledException("Selected update is not uninstallable");
            }
            Console.WriteLine("Uninstall successful");
        }
Exemplo n.º 3
0
        public IUpdateCollection GetAvailableUpdates()
        {
            var             uSession  = new UpdateSessionClass();
            IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();

            Logger.DebugFormat("Searcher server selection: " + uSearcher.ServerSelection);
            Logger.DebugFormat("Searcher service ID: " + uSearcher.ServiceID);

            uSearcher.Online = false;
            ISearchResult uResult = uSearcher.Search("IsInstalled=0 and Type='Software'");

            return(uResult.Updates);
        }
Exemplo n.º 4
0
        public void CountPendingUpdates()
        {
            Console.WriteLine("WUA_Starting");

            IUpdateSession updateSession = new UpdateSessionClass();

            IUpdateSearcher   updateSearcher   = updateSession.CreateUpdateSearcher();
            IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
            IUpdateInstaller  updateInstaller  = updateSession.CreateUpdateInstaller();

            // SEARCHING

            Console.WriteLine("WUA_FindingUpdates");

            ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'");

            Console.WriteLine(string.Format("WUA_Pending:{0}", searchResult.Updates.Count));

            Console.WriteLine("WUA_Finish");
        }
Exemplo n.º 5
0
        static void GetInstalledUpdates()
        {
            UpdateSessionClass uSession = new UpdateSessionClass();
            IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
            ISearchResult uResult = uSearcher.Search("IsInstalled=1 and Type='Software'");
            List<IUpdate> results = new List<IUpdate>{ };
            foreach (IUpdate update in uResult.Updates)
            {
                results.Add(update);
            }
            results = results.OrderBy(x => Convert.ToInt32(x.KBArticleIDs[0]))
                             .ToList();
            PrintRow("KB Article", "Description", "Severity");
            PrintLine();

            foreach (IUpdate update in results)
            {
                PrintRow(update.KBArticleIDs[0], update.Title, update.MsrcSeverity);
            }
            PrintLine();
        }
Exemplo n.º 6
0
        static void GetInstalledUpdates()
        {
            UpdateSessionClass uSession  = new UpdateSessionClass();
            IUpdateSearcher    uSearcher = uSession.CreateUpdateSearcher();
            ISearchResult      uResult   = uSearcher.Search("IsInstalled=1 and Type='Software'");
            List <IUpdate>     results   = new List <IUpdate> {
            };

            foreach (IUpdate update in uResult.Updates)
            {
                results.Add(update);
            }
            results = results.OrderBy(x => Convert.ToInt32(x.KBArticleIDs[0]))
                      .ToList();
            PrintRow("KB Article", "Description", "Severity");
            PrintLine();

            foreach (IUpdate update in results)
            {
                PrintRow(update.KBArticleIDs[0], update.Title, update.MsrcSeverity);
            }
            PrintLine();
        }
Exemplo n.º 7
0
        public static void WriteUpdateList()
        {
            var wuaSession  = new UpdateSessionClass();
            var wuaSearcher = wuaSession.CreateUpdateSearcher();
            var wuaSearch   = wuaSearcher.Search("IsInstalled=1 and IsPresent=1 and Type='Software'");
            var updates     = wuaSearch.Updates.OfType <IUpdate>().ToList();

            var first = true;

            foreach (var update in updates)
            {
                if (!first)
                {
                    Console.WriteLine();
                }
                first = false;

                var id = update.Identity;
                Console.WriteLine(nameof(id.UpdateID) + " - " + id.UpdateID);
                Console.WriteLine(nameof(id.RevisionNumber) + " - " +
                                  id.RevisionNumber.ToString(CultureInfo.InvariantCulture));

                Console.WriteLine(nameof(update.Title) + " - " + update.Title);
                Console.WriteLine(nameof(update.IsUninstallable) + " - " +
                                  update.IsUninstallable.ToString(CultureInfo.InvariantCulture));

                Console.WriteLine(nameof(update.SupportUrl) + " - " + update.SupportUrl);

                Console.WriteLine(nameof(update.MinDownloadSize) + " - " +
                                  update.MinDownloadSize.ToString(CultureInfo.InvariantCulture));
                Console.WriteLine(nameof(update.MaxDownloadSize) + " - " +
                                  update.MaxDownloadSize.ToString(CultureInfo.InvariantCulture));
                Console.WriteLine(nameof(update.LastDeploymentChangeTime) + " - " +
                                  update.LastDeploymentChangeTime.ToString(CultureInfo.InvariantCulture));
            }
        }
Exemplo n.º 8
0
        public void Start(bool showProgress)
        {
            this.ShowProgress = showProgress;

            Console.WriteLine("WUA_Starting");

            IUpdateSession updateSession = new UpdateSessionClass();

            IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();
            IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
            IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller();

            if (updateInstaller.IsBusy)
            {
                Console.WriteLine("WUA_IsBusy");
                return;
            }

            // SEARCHING

            Console.WriteLine("WUA_FindingUpdates");

            ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'");

            if (searchResult.Updates.Count.Equals(0))
            {
                Console.WriteLine("WUA_NoApplicableUpdates");
                return;
            }

            // LISTING

            UpdateCollection updateToDownload = new UpdateCollectionClass();

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdate update = searchResult.Updates[i];

                Console.WriteLine("WUA_UpdateItem:{0}|{1}", i + 1, update.Title);

                if (!update.IsDownloaded)
                {
                    updateToDownload.Add(update);
                }
            }

            // DOWNLOADING

            if (!updateToDownload.Count.Equals(0))
            {
                Console.WriteLine("WUA_DownloadingStarted");

                updateDownloader.Updates = updateToDownload;
                updateDownloader.IsForced = true;
                updateDownloader.Priority = DownloadPriority.dpHigh;

                IDownloadJob job = updateDownloader.BeginDownload(this, this, updateDownloader);
                IDownloadResult downloaderResult = updateDownloader.EndDownload(job);

                Console.WriteLine("WUA_DownloadingCompleted:{0}", downloaderResult.ResultCode);
            }

            // INSTALLATION

            updateInstaller.Updates = searchResult.Updates;
            updateInstaller.IsForced = true;

            Console.WriteLine("WUA_InstallationStarted");

            IInstallationJob installationJob = updateInstaller.BeginInstall(this, this, updateInstaller);
            IInstallationResult result = updateInstaller.EndInstall(installationJob);

            Console.WriteLine("WUA_InstallationCompleted:{0}|{1}", result.ResultCode, result.RebootRequired);

            // RESULT

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdateInstallationResult resultItem = result.GetUpdateResult(i);
                Console.WriteLine("WUA_InstallationResult:{0}|{1}|{2}",
                    i + 1, resultItem.ResultCode, resultItem.RebootRequired);
            }

            Console.WriteLine("WUA_Finish");
        }
Exemplo n.º 9
0
        public void Start(bool showProgress)
        {
            this.ShowProgress = showProgress;

            Console.WriteLine("WUA_Starting");

            IUpdateSession updateSession = new UpdateSessionClass();

            IUpdateSearcher   updateSearcher   = updateSession.CreateUpdateSearcher();
            IUpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
            IUpdateInstaller  updateInstaller  = updateSession.CreateUpdateInstaller();

            if (updateInstaller.IsBusy)
            {
                Console.WriteLine("WUA_IsBusy");
                return;
            }

            // SEARCHING

            Console.WriteLine("WUA_FindingUpdates");

            ISearchResult searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'");

            if (searchResult.Updates.Count.Equals(0))
            {
                Console.WriteLine("WUA_NoApplicableUpdates");
                return;
            }

            // LISTING

            UpdateCollection updateToDownload = new UpdateCollectionClass();

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdate update = searchResult.Updates[i];

                Console.WriteLine("WUA_UpdateItem:{0}|{1}", i + 1, update.Title);

                if (!update.IsDownloaded)
                {
                    updateToDownload.Add(update);
                }
            }

            // DOWNLOADING

            if (!updateToDownload.Count.Equals(0))
            {
                Console.WriteLine("WUA_DownloadingStarted");

                updateDownloader.Updates  = updateToDownload;
                updateDownloader.IsForced = true;
                updateDownloader.Priority = DownloadPriority.dpHigh;

                IDownloadJob    job = updateDownloader.BeginDownload(this, this, updateDownloader);
                IDownloadResult downloaderResult = updateDownloader.EndDownload(job);

                Console.WriteLine("WUA_DownloadingCompleted:{0}", downloaderResult.ResultCode);
            }

            // INSTALLATION

            updateInstaller.Updates  = searchResult.Updates;
            updateInstaller.IsForced = true;

            Console.WriteLine("WUA_InstallationStarted");

            IInstallationJob    installationJob = updateInstaller.BeginInstall(this, this, updateInstaller);
            IInstallationResult result          = updateInstaller.EndInstall(installationJob);

            Console.WriteLine("WUA_InstallationCompleted:{0}|{1}", result.ResultCode, result.RebootRequired);

            // RESULT

            for (int i = 0; i < searchResult.Updates.Count; i++)
            {
                IUpdateInstallationResult resultItem = result.GetUpdateResult(i);
                Console.WriteLine("WUA_InstallationResult:{0}|{1}|{2}",
                                  i + 1, resultItem.ResultCode, resultItem.RebootRequired);
            }

            Console.WriteLine("WUA_Finish");
        }
Exemplo n.º 10
0
 // Token: 0x06000003 RID: 3 RVA: 0x000020E8 File Offset: 0x000002E8
 public void DoUpdate()
 {
     if (this.ConsoleDiagnostics)
     {
         Console.WriteLine("Checking for Updates.");
     }
     try
     {
         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StartScan, null, new string[0]);
         IUpdateSession updateSession = new UpdateSessionClass();
         updateSession.ClientApplicationID = "Exchange12";
         IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();
         ISearchResult   searchResult   = updateSearcher.Search("IsInstalled=0 and CategoryIDs contains 'ab62c5bd-5539-49f6-8aea-5a114dd42314'");
         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StopScan, null, new string[0]);
         if (searchResult.Updates.Count == 0)
         {
             if (this.ConsoleDiagnostics)
             {
                 Console.WriteLine("No Updates.");
             }
         }
         else
         {
             foreach (object obj in searchResult.Updates)
             {
                 IUpdate update = (IUpdate)obj;
                 UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_PatchAvailable, null, new string[]
                 {
                     update.Title
                 });
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Title: {0}", update.Title);
                 }
             }
             UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StartDownload, null, new string[0]);
             UpdateDownloader updateDownloader = updateSession.CreateUpdateDownloader();
             updateDownloader.Priority = 3;
             updateDownloader.Updates  = searchResult.Updates;
             IDownloadResult downloadResult = updateDownloader.Download();
             UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StopDownload, null, new string[0]);
             for (int i = 0; i < updateDownloader.Updates.Count; i++)
             {
                 if (downloadResult.GetUpdateResult(i).ResultCode == 4 || downloadResult.GetUpdateResult(i).ResultCode == 5)
                 {
                     UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_DownloadFailure, null, new string[]
                     {
                         updateDownloader.Updates[i].Title,
                         downloadResult.GetUpdateResult(i).HResult.ToString()
                     });
                     if (this.ConsoleDiagnostics)
                     {
                         Console.WriteLine("Errors: {0}: {1}", updateDownloader.Updates[i].Title, downloadResult.GetUpdateResult(i).HResult);
                     }
                 }
             }
             bool flag = false;
             foreach (object obj2 in updateDownloader.Updates)
             {
                 IUpdate update2 = (IUpdate)obj2;
                 if (update2.IsDownloaded)
                 {
                     flag = true;
                 }
             }
             if (!flag)
             {
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Nothing to Install.");
                 }
             }
             else
             {
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Starting Installation.");
                 }
                 UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StartInstall, null, new string[0]);
                 IUpdateInstaller updateInstaller = updateSession.CreateUpdateInstaller();
                 updateInstaller.Updates = updateDownloader.Updates;
                 IInstallationResult installationResult = updateInstaller.Install();
                 UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_StopInstall, null, new string[0]);
                 for (int j = 0; j < updateInstaller.Updates.Count; j++)
                 {
                     IUpdate update3 = updateInstaller.Updates[j];
                     if (installationResult.GetUpdateResult(j).ResultCode == 4 || installationResult.GetUpdateResult(j).ResultCode == 3)
                     {
                         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_InstallFailure, null, new string[]
                         {
                             updateInstaller.Updates[j].Title,
                             installationResult.GetUpdateResult(j).HResult.ToString()
                         });
                         if (this.ConsoleDiagnostics)
                         {
                             Console.WriteLine("Errors: {0}: {1}", updateInstaller.Updates[j].Title, installationResult.GetUpdateResult(j).HResult);
                         }
                     }
                 }
                 if (this.ConsoleDiagnostics)
                 {
                     Console.WriteLine("Finished.");
                 }
             }
         }
     }
     catch (COMException ex)
     {
         UpdateSvcEventLogger.LogEvent(AntispamUpdateServiceEventLogConstants.Tuple_WuaFail, null, new string[]
         {
             ex.Message
         });
         if (this.ConsoleDiagnostics)
         {
             Console.WriteLine("Failed: {0}", ex.Message);
         }
     }
 }
Exemplo n.º 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists("Backup"))
            {
                Directory.CreateDirectory("Backup");
                if (Directory.Exists("Rads"))
                {
                    DirectoryInfo airinfo = new DirectoryInfo(airr);
                    DirectoryInfo air = airinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo slninfo = new DirectoryInfo(slnr);
                    DirectoryInfo sln = slninfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo launchinfo = new DirectoryInfo(launchr);
                    DirectoryInfo launch = launchinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo gameinfo = new DirectoryInfo(gamer);
                    DirectoryInfo game = gameinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    string gamez = @"RADS\projects\lol_game_client\releases\" + game + @"\deploy";
                    string airz = @"RADS\projects\lol_air_client\releases\" + air + @"\deploy\Adobe AIR\Versions\1.0";

                    File.Copy(gamez + @"\cg.dll", @"Backup\cg.dll", true);
                    File.Copy(gamez + @"\cgd3d9.dll", @"Backup\cgd3d9.dll", true);
                    File.Copy(gamez + @"\cggl.dll", @"Backup\cggl.dll", true);
                    File.Copy(gamez + @"\tbb.dll", @"Backup\tbb.dll", true);
                    File.Copy(airz + @"\Resources\NPSWF32.dll", @"Backup\NPSWF32.dll", true);
                    File.Copy(airz + @"\Adobe Air.dll", @"Backup\Adobe Air.dll", true);
                    if (File.Exists(@"Config\game.cfg"))
                    {
                        File.Copy(@"Config\game.cfg", @"Backup\game.cfg", true);
                    }
                }
                else if (Directory.Exists("Game"))
                {
                    Directory.CreateDirectory("Backup");
                    File.Copy(@"game\cg.dll", @"Backup\cg.dll", true);
                    File.Copy(@"game\cgd3d9.dll", @"Backup\cgd3d9.dll", true);
                    File.Copy(@"game\cggl.dll", @"Backup\cggl.dll", true);
                    File.Copy(@"game\tbb.dll", @"Backup\tbb.dll", true);
                    File.Copy(@"Air\Adobe Air\Versions\1.0\Resources\NPSWF32.dll", @"Backup\NPSWF32.dll", true);
                    File.Copy(@"Air\Adobe Air\Versions\1.0\Adobe Air.dll", @"Backup\Adobe Air.dll", true);
                    if (File.Exists(@"Game\DATA\CFG\defaults\game.cfg"))
                    {
                        File.Copy(@"Game\DATA\CFG\defaults\game.cfg", @"Backup\game.cfg", true);
                        File.Copy(@"Game\DATA\CFG\defaults\gamepermanent.cfg", @"Backup\gamepermanent.cfg", true);
                        if (File.Exists(@"Game\DATA\CFG\defaults\GamePermanent_zh_MY.cfg"))
                        {
                            File.Copy(@"Game\DATA\CFG\defaults\GamePermanent_zh_MY.cfg", @"Backup\GamePermanent_zh_MY.cfg", true);
                        }
                        if (File.Exists(@"Game\DATA\CFG\defaults\GamePermanent_en_SG.cfg"))
                        {
                            File.Copy(@"Game\DATA\CFG\defaults\GamePermanent_en_SG.cfg", @"Backup\GamePermanent_en_SG.cfg", true);
                        }

                    }
                }
            }

            var windir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
            string root = System.IO.Path.GetPathRoot(Environment.SystemDirectory);
            RegistryKey keycg = Registry.LocalMachine;
            RegistryKey subKeycg = keycg.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Cg Toolkit_is1");
            var CG = subKeycg.GetValue("InstallLocation") + @"bin\";
            if (Cleantemp.Checked)
            {
                var cm = new ProcessStartInfo();
                cm.FileName = "cleanmgr";
                cm.Arguments = "sagerun:1";
                cm.Verb = "runas";
                var process = new Process();
                process.StartInfo = cm;
                process.Start();
                process.WaitForExit();
            }
            if (Cleanupdatecache.Checked)
            {
                ServiceController updateservice = new ServiceController("wuauserv");
                switch (updateservice.Status)
                {
                    case ServiceControllerStatus.Running:
                        updateservice.Stop();
                        updateservice.WaitForStatus(ServiceControllerStatus.Stopped);
                        Directory.Delete(windir + @"\SoftwareDistribution", true);
                        updateservice.Start();
                        updateservice.WaitForStatus(ServiceControllerStatus.Running);
                        break;
                    case ServiceControllerStatus.Stopped:
                        Directory.Delete(windir + @"\SoftwareDistribution", true);
                        updateservice.Start();
                        updateservice.WaitForStatus(ServiceControllerStatus.Running);
                        break;
                }
            }
            if (UninstallPMB.Checked)
            {
                using (RegistryKey Key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Pando Networks\\PMB"))
                    if (Key != null)
                    {
                        RegistryKey key = Registry.LocalMachine;
                        RegistryKey subKey = key.OpenSubKey("SOFTWARE\\Wow6432Node\\Pando Networks\\PMB");
                        var PMB = subKey.GetValue("Program Directory").ToString();
                        var psi2 = new ProcessStartInfo();
                        psi2.FileName = PMB + @"\uninst.exe";
                        psi2.Verb = "runas";
                        var PMBUninstallProc = new Process();
                        PMBUninstallProc.StartInfo = psi2;
                        PMBUninstallProc.Start();
                        PMBUninstallProc.WaitForExit();
                    }
                    else
                    {
                        MessageBox.Show("Pando Media Booster is already Uninstalled");
                    }
            }
            var allServices = new Dictionary<string, string[]>
            {
            { "6.3", new[] { "Appmgmt", "bthserv", "PeerDistSvc", "NfsClnt", "TrkWks", "WPCSvc", "vmickvpexchange", "vmicguestinterface", "vmicshutdown", "vmicheartbeat", "vmicrdv", "vmictimesync", "vmicvss", "IEEtwCollectorService", "iphlpsvc", "Netlogon", "CscService", "RpcLocator", "MSiSCSI", "SensrSvc", "ScDeviceEnum", "SCPolicySvc", "SNMPTRAP", "StorSvc", "WbioSrvc", "wcncsvc", "fsvc", "WMPNetworkSvc" } },
            { "6.2", new[] { "WMPNetworkSvc", "wcncsvc", "WbioSrvc", "StorSvc", "SNMPTRAP", "SCPolicySvc", "SensrSvc", "RpcLocator", "CscService", "Netlogon", "MSiSCSI", "iphlpsvc", "vmicvss", "vmictimesync", "vmicrdv", "vmicheartbeat", "vmicshutdown", "vmickvpexchange", "WPCSvc", "TrkWks", "NfsClnt", "CertPropSvc", "PeerDistSvc", "bthserv", "Appmgmt" } },
            { "6.1", new[] {"WSearch", "WMPNetworkSvc", "wcncsvc", "StorSvc", "SNMPTRAP", "SCPolicySvc", "SCardSvr", "RemoteRegistry", "RpcLocator", "WPCSvc", "CscService", "napagent", "Netlogon", "MSiSCSI", "iphlpsvc", "TrkWks", "CertPropSvc", "bthserv", "AppMgmt" } },
            { "6.0", new[] { "TrkWks", "WinHttpAutoProxySvc", "WSearch", "WinRM", "WebClient", "UmRdpService", "TabletInputService", "SNMPTRAP", "SCPolicySvc", "SCardSvr", "RemoteRegistry", "CscService", "Netlogon", "MSiSCSI", "iphlpsvc", "Fax", "CertPropSvc" } },
            { "5.1", new[] { "WmiApSrv", "W32Time", "WebClient", "UPS", "Netlogon", "SCardSvr", "TlntSvr", "seclogon", "RemoteRegistry", "RDSessMgr", "RSVP", "WmdmPmSN", "xmlprov", "mnmsrvc", "cisvc", "ERSvc" } }
            };
            string[] services;
            if (WindowsServices.Checked && allServices.TryGetValue(Environment.OSVersion.Version.ToString(), out services))
            {
                services.ToList().ForEach(service => ServiceHelper.ChangeStartMode(new ServiceController(service), ServiceStartMode.Manual));
            }
            if (Mousepollingrate.Checked)
            {
                Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers");
                RegistryKey mousehz = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", true);
                mousehz.SetValue("C:\\Windows\\Explorer.exe", "NoDTToDITMouseBatch");
                System.Diagnostics.Process applymouseHz = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Verb = "runas";
                startInfo.Arguments = @"/C Rundll32 apphelp.dll , ShimFlushCache";
                applymouseHz.StartInfo = startInfo;
                applymouseHz.Start();
                applymouseHz.WaitForExit();
            }
            if (Defrag.Checked)
            {
                System.Diagnostics.Process defrag = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = "dfrgui.exe";
                startInfo.Verb = "runas";
                defrag.StartInfo = startInfo;
                defrag.Start();
                defrag.WaitForExit();
            }
            if (WindowsUpdate.Checked)
            {
                UpdateSessionClass uSession = new UpdateSessionClass();
                IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
                ISearchResult uResult = uSearcher.Search(@"IsInstalled=0 and
            Type='Software' and IsHidden=0 and BrowseOnly=1 and AutoSelectOnWebSites=1 and RebootRequired=0");
                UpdateDownloader downloader = uSession.CreateUpdateDownloader();
                downloader.Updates = uResult.Updates;
                downloader.Download();
                UpdateCollection updatesToInstall = new UpdateCollection();
                foreach (IUpdate update in uResult.Updates)
                {
                    if (update.IsDownloaded)
                        updatesToInstall.Add(update);
                }
                IUpdateInstaller installer = uSession.CreateUpdateInstaller();
                installer.Updates = updatesToInstall;
                IInstallationResult installationRes = installer.Install();
            }
            if (Deleteoldlogs.Checked)
            {
                if (Directory.Exists("Logs"))
                {
                    string[] files = Directory.GetFiles("Logs");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.LastAccessTime < DateTime.Now.AddDays(-7))
                            fi.Delete();
                    }
                }
            }
            if (Patcher.Checked)
            {
                int coreCount = 0;
                foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
                {
                    coreCount += int.Parse(item["NumberOfCores"].ToString());
                }
                if (coreCount >= 2)
                {

                    if (File.Exists(@"Config\game.cfg"))
                    {
                        File.AppendAllText(@"Config\game.cfg", Environment.NewLine + "DefaultParticleMultithreading=1");
                    }

                    else if (File.Exists(@"Game\DATA\CFG\defaults\game.cfg"))
                    {
                        File.AppendAllText(@"Game\DATA\CFG\defaults\game.cfg", Environment.NewLine + "DefaultParticleMultithreading=1");
                        File.AppendAllText(@"Game\DATA\CFG\defaults\GamePermanent.cfg", Environment.NewLine + "DefaultParticleMultithreading=1");
                        File.AppendAllText(@"Game\DATA\CFG\defaults\GamePermanent_zh_MY.cfg", Environment.NewLine + "DefaultParticleMultithreading=1");
                        File.AppendAllText(@"Game\DATA\CFG\defaults\GamePermanent_en_SG.cfg", Environment.NewLine + "DefaultParticleMultithreading=1");

                    }

                }
                if (Directory.Exists("Rads"))
                {
                    DirectoryInfo airinfo = new DirectoryInfo(airr);
                    DirectoryInfo air = airinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo slninfo = new DirectoryInfo(slnr);
                    DirectoryInfo sln = slninfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo launchinfo = new DirectoryInfo(launchr);
                    DirectoryInfo launch = launchinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo gameinfo = new DirectoryInfo(gamer);
                    DirectoryInfo game = gameinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    string gamez = @"RADS\projects\lol_game_client\releases\" + game + @"\deploy";
                    string airz = @"RADS\projects\lol_air_client\releases\" + air + @"\deploy\Adobe AIR\Versions\1.0";
                    string slnz = @"RADS\solutions\lol_game_client_sln\releases\" + sln + @"\deploy";
                    string launchz = @"RADS\projects\lol_launcher\releases\" + launch + @"\deploy";
                    System.IO.File.WriteAllBytes(gamez + @"\tbb.dll", LoLUpdater.Properties.Resources.tbb);
                    File.Copy(CG + @"\cg.dll", gamez + @"\cg.dll", true);
                    File.Copy(CG + @"\cgd3d9.dll", gamez + @"\cgd3d9.dll", true);
                    File.Copy(CG + @"\cggl.dll", gamez + @"\cggl.dll", true);
                    File.Copy(CG + @"\cg.dll", launchz + @"\cg.dll", true);
                    File.Copy(CG + @"\cgd3d9.dll", launchz + @"\cgd3d9.dll", true);
                    File.Copy(CG + @"\cggl.dll", launchz + @"\cggl.dll", true);
                    System.IO.File.WriteAllBytes(slnz + @"\tbb.dll", LoLUpdater.Properties.Resources.tbb);
                    File.Copy(CG + @"\cg.dll", slnz + @"\cg.dll", true);
                    File.Copy(CG + @"\cgd3d9.dll", slnz + @"\cgd3d9.dll", true);
                    File.Copy(CG + @"\cggl.dll", slnz + @"\cggl.dll", true);
                    System.IO.File.WriteAllBytes(airz + @"\Resources\NPSWF32.dll", LoLUpdater.Properties.Resources.NPSWF32);
                    System.IO.File.WriteAllBytes(airz + @"\Adobe Air.dll", LoLUpdater.Properties.Resources.Adobe_AIR);
                }
                else if (Directory.Exists("Game"))
                {
                    System.IO.File.WriteAllBytes(@"game\tbb.dll", LoLUpdater.Properties.Resources.tbb);
                    File.Copy(CG + @"\cg.dll", @"game\cg.dll", true);
                    File.Copy(CG + @"\cgd3d9.dll", @"game\cgd3d9.dll", true);
                    File.Copy(CG + @"\cggl.dll", @"game\cggl.dll", true);
                    System.IO.File.WriteAllBytes(@"Air\Adobe Air\Versions\1.0\Resources\NPSWF32.dll", LoLUpdater.Properties.Resources.NPSWF32);
                    System.IO.File.WriteAllBytes(@"Air\Adobe Air\Versions\1.0\Adobe Air.dll", LoLUpdater.Properties.Resources.Adobe_AIR);
                }
                System.Windows.Forms.MessageBox.Show("Finished!");
            }
            else if (Restorebackups.Checked)
            {
                if (Directory.Exists("Rads"))
                {
                    DirectoryInfo airinfo = new DirectoryInfo(airr);
                    DirectoryInfo air = airinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo slninfo = new DirectoryInfo(slnr);
                    DirectoryInfo sln = slninfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo launchinfo = new DirectoryInfo(launchr);
                    DirectoryInfo launch = launchinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    DirectoryInfo gameinfo = new DirectoryInfo(gamer);
                    DirectoryInfo game = gameinfo.GetDirectories()
                    .OrderByDescending(d => d.CreationTime)
                    .FirstOrDefault();
                    string gamez = @"RADS\projects\lol_game_client\releases\" + game + @"\deploy";
                    string airz = @"RADS\projects\lol_air_client\releases\" + air + @"\deploy\Adobe AIR\Versions\1.0";
                    string slnz = @"RADS\solutions\lol_game_client_sln\releases\" + sln + @"\deploy";
                    string launchz = @"RADS\projects\lol_launcher\releases\" + launch + @"\deploy";
                    File.Copy(@"Backup\cg.dll", gamez + @"\cg.dll", true);
                    File.Copy(@"Backup\cgd3d9.dll", gamez + @"\cgd3d9.dll", true);
                    File.Copy(@"Backup\cggl.dll", gamez + @"\cggl.dll", true);
                    File.Copy(@"Backup\tbb.dll", gamez + @"\tbb.dll", true);
                    File.Copy(@"Backup\cg.dll", slnz + @"\cg.dll", true);
                    File.Copy(@"Backup\cgd3d9.dll", slnz + @"\cgd3d9.dll", true);
                    File.Copy(@"Backup\cggl.dll", slnz + @"\cggl.dll", true);
                    File.Copy(@"Backup\tbb.dll", slnz + @"\tbb.dll", true);
                    File.Copy(@"Backup\cg.dll", launchz + @"\cg.dll", true);
                    File.Copy(@"Backup\cgd3d9.dll", launchz + @"\cgd3d9.dll", true);
                    File.Copy(@"Backup\cggl.dll", launchz + @"\cggl.dll", true);
                    File.Copy(@"Backup\NPSWF32.dll", airz + @"\Resources\NPSWF32.dll", true);
                    File.Copy(@"Backup\Adobe Air.dll", airz + @"\Adobe Air.dll", true);
                    if (File.Exists(@"Backup\game.cfg"))
                    {
                        File.Copy(@"Backup\game.cfg", @"Config\game.cfg", true);
                    }
                }
                else if (Directory.Exists("Game"))
                {
                    File.Copy(@"Backup\cg.dll", @"game\cg.dll", true);
                    File.Copy(@"Backup\cgd3d9.dll", @"game\cgd3d9.dll", true);
                    File.Copy(@"Backup\cggl.dll", @"game\cggl.dll", true);
                    File.Copy(@"Backup\tbb.dll", @"game\tbb.dll", true);
                    File.Copy(@"Backup\NPSWF32.dll", @"AIR\Adobe Air\Versions\1.0\Resources\NPSWF32.dll", true);
                    File.Copy(@"Backup\Adobe Air.dll", @"AIR\Adobe Air\Versions\1.0\Adobe Air.dll", true);
                    if (File.Exists(@"Game\DATA\CFG\defaults\game.cfg"))
                    {
                        File.Copy(@"Backup\game.cfg", @"Game\DATA\CFG\defaults\game.cfg", true);
                        File.Copy(@"Backup\gamepermanent.cfg", @"Game\DATA\CFG\defaults\gamepermanent.cfg", true);
                        if (File.Exists(@"Backup\GamePermanent_zh_MY.cfg"))
                        {
                            File.Copy(@"Backup\GamePermanent_zh_MY.cfg", @"Game\DATA\CFG\defaults\GamePermanent_zh_MY.cfg", true);

                            if (File.Exists(@"Backup\GamePermanent_en_SG.cfg"))
                            {
                                File.Copy(@"Game\DATA\CFG\defaults\GamePermanent_en_SG.cfg", @"Game\DATA\CFG\defaults\GamePermanent_en_SG.cfg", true);
                            }

                        }
                    }
                    System.Windows.Forms.MessageBox.Show("Finished!");
                }

                else if (onlycheckboxes.Checked)
                {
                    System.Windows.Forms.MessageBox.Show("Finished!");

                }
            }
        }