コード例 #1
0
        private void BtnEventsCleaner_Click(object sender, RoutedEventArgs e)
        {
            Button btnEvent = (Button)sender;

            btnEvent.IsEnabled = false;
            string batPath = Path.Combine(Path.GetTempPath(), "Clean_EventLogs.bat");

            if (File.Exists(batPath))
            {
                File.Delete(batPath);
            }
            using (StreamWriter sw = File.CreateText(batPath))
            {
                sw.WriteLine("@echo off");
                sw.WriteLine("FOR /F \"tokens=1,2*\" %%V IN ('bcdedit') DO SET adminTest=%%V");
                sw.WriteLine("IF (%adminTest%)==(Access) goto noAdmin");
                sw.WriteLine("for /F \"tokens=*\" %%G in ('wevtutil.exe el') DO (call :do_clear \"%%G\")");
                sw.WriteLine("echo.");
                sw.WriteLine("echo goto theEnd");
                sw.WriteLine(":do_clear");
                sw.WriteLine("echo clearing %1");
                sw.WriteLine("wevtutil.exe cl %1");
                sw.WriteLine("goto :eof");
                sw.WriteLine(":noAdmin");
                sw.WriteLine("exit");
            }

            CustomProc.StartProc(batPath, exMsg: "There was an error clearing event logs.\n");
            File.Delete(batPath);
            btnEvent.IsEnabled = true;
        }
コード例 #2
0
        private static void IconRebuild(IProgress <int> progress)
        {
            int c = 0;

            progress.Report(c += 25);
            try
            {
                string env = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                if (env.Length == 0)
                {
                    return;
                }
                foreach (Process proc in Process.GetProcessesByName("explorer"))
                {
                    proc.Kill();
                }
                progress.Report(c += 25);
                try
                {
                    File.Delete(Path.Combine(env, "IconCache.db"));
                }
                catch
                {
                    //ignored
                }

                progress.Report(c += 25);

                foreach (string f in Directory.GetFiles(
                             Path.Combine(env, @"Microsoft\Windows\Explorer"), "iconcache*"))
                {
                    try
                    {
                        File.Delete(f);
                    }
                    catch
                    {
                        //ignored
                    }
                }

                progress.Report(c);
                if (Process.GetProcessesByName("explorer").Length == 0)
                {
                    CustomProc.StartProc("explorer.exe");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
            finally
            {
                progress.Report(100);
            }
        }
コード例 #3
0
        private static void FontRebuild(IProgress <int> progress)
        {
            int c = 0;

            progress.Report(c += 25);
            const string servName = "FontCache";

            try
            {
                string env = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                Shared.ServiceStartType(servName, "4");
                Shared.ServiceRestarter(servName, false);
                progress.Report(c += 25);
                CustomProc.StartProc("cmd.exe",
                                     @"/C icacls ""%WinDir%\ServiceProfiles\LocalService"" /grant ""%UserName%"":F /C /T /Q",
                                     ProcessWindowStyle.Hidden);
                string font1 = Path.Combine(env, @"System32\FNTCACHE.DAT");
                progress.Report(c += 25);
                try
                {
                    File.Delete(font1);
                }
                catch
                {
                    //ignored
                }

                progress.Report(c);

                foreach (string f in Directory.GetFiles(
                             Path.Combine(env, @"ServiceProfiles\LocalService\AppData\Local\FontCache"), "*FontCache*"))
                {
                    try
                    {
                        File.Delete(f);
                    }
                    catch
                    {
                        //ignored
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
            finally
            {
                Shared.ServiceStartType(servName, "2", "0");
                Shared.ServiceRestarter(servName, true);
                progress.Report(100);
            }
        }
コード例 #4
0
 private void OpenDirCmd_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         foreach (SoftwareModel item in LvSoftware.SelectedItems)
         {
             CustomProc.StartProc(item.Location, wait: false);
         }
     }
     catch
     {
         //ignored
     }
 }
コード例 #5
0
 private void OpenDirCmd_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         foreach (StartupModel item in LvAutoruns.SelectedItems)
         {
             string dirFull = Path.GetDirectoryName(item.Path);
             if (dirFull != null)
             {
                 CustomProc.StartProc(dirFull, wait: false);
             }
         }
     }
     catch
     {
         //ignored
     }
 }
コード例 #6
0
 private void OpenRegCmd_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         foreach (SoftwareModel item in LvSoftware.SelectedItems)
         {
             Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit",
                               "LastKey",
                               item.RegPath);
             // Need 64-bit Process v3.0
             CustomProc.StartProc("regedit", "-m", wait: false);
         }
     }
     catch
     {
         // ignored
     }
 }
コード例 #7
0
        private async void DeleteCmd_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            int selCount = LvAddons.SelectedItems.Count;

            if (selCount > 20)
            {
                object result = await DialogHost.Show(
                    new GenYesNoUc($"Are you sure you want to delete {selCount} items?"), "RootDialog");

                if (result == null || result.ToString() != "Y")
                {
                    return;
                }
            }

            if (Process.GetProcessesByName("chrome").Length > 0)
            {
                object result = await DialogHost.Show(new ChromeProcessUc(), "RootDialog");

                if (result == null || result.ToString() != "Y")
                {
                    return;
                }
                CustomProc.KillAllProc("chrome");
            }

            for (int index = selCount - 1; index >= 0; index--)
            {
                AddonModel item = (AddonModel)LvAddons.SelectedItems[index];
                try
                {
                    Directory.Delete(Path.Combine(item.Path, item.Id), true);
                    _addonList.Remove(item);
                }
                catch
                {
                    //ignored
                }
            }
        }
コード例 #8
0
        private async void MsiCmd_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            int selCount = LvSoftware.SelectedItems.Count;

            if (selCount > 20)
            {
                object result = await DialogHost.Show(
                    new GenYesNoUc($"Are you sure you want to work with {selCount} items?"), "RootDialog");

                if (result == null || result.ToString() != "Y")
                {
                    return;
                }
            }

            for (int index = selCount - 1; index >= 0; index--)
            {
                SoftwareModel item           = (SoftwareModel)LvSoftware.SelectedItems[index];
                string        msiExec        = item.Uninstall;
                int           separatorIndex = msiExec.IndexOf(".exe", StringComparison.Ordinal);
                if (separatorIndex < 1)
                {
                    return;
                }
                string arg = msiExec.Substring(separatorIndex + 4);
                msiExec = msiExec.Substring(0, separatorIndex + 4);
                switch (e.Parameter)
                {
                case "Change":
                    arg = arg.Replace("/X", "/I");
                    CustomProc.StartProc(msiExec, arg);
                    break;

                case "Repair":
                    arg = arg.Replace("/X", "/I").Replace("/I", "/F ");
                    CustomProc.StartProc(msiExec, arg);
                    break;
                }
            }
        }
コード例 #9
0
ファイル: EffImage.cs プロジェクト: likia/Imprint.Kernel
        /// <summary>
        /// 每个像素进行处理
        ///
        /// </summary>
        /// <param name="proc">回调</param>
        /// <param name="linefirst">是否一行一行遍历</param>
        /// <param name="parallel">是否并行, 发挥多核cpu性能, 适合大图片, 小图片反而增加开销</param>
        public void ProcessEach(CustomProc proc, bool linefirst = true, bool?parallel = null)
        {
            int fstLim = 0, lstLim = 0;

            if (parallel == null)
            {
                parallel = useParalle;
            }

            if (linefirst)
            {
                fstLim = width;
                lstLim = height;
            }
            else
            {
                fstLim = height;
                lstLim = width;
            }
            if (parallel == true)
            {
                Parallel.For(0, fstLim, (i) =>
                {
                    Parallel.For(0, lstLim, (j) =>
                    {
                        proc(this, i, j);
                    });
                });
            }
            else
            {
                for (int i = 0; i < fstLim; i++)
                {
                    for (int j = 0; j < lstLim; j++)
                    {
                        proc(this, i, j);
                    }
                }
            }
        }
コード例 #10
0
        private void BtnTelemetryYes_Click(object sender, RoutedEventArgs e)
        {
            string batPath = Path.Combine(Path.GetTempPath(), "Uninstall_Telemetry_Updates.bat");

            if (File.Exists(batPath))
            {
                File.Delete(batPath);
            }
            using (StreamWriter sw = File.CreateText(batPath))
            {
                sw.WriteLine("@echo off");
                foreach (string up in _updates)
                {
                    sw.WriteLine("start /w wusa.exe /uninstall /kb:" + up.Replace("KB", "") + " /quiet /norestart");
                }

                sw.WriteLine("exit");
            }

            CustomProc.StartProc(batPath, exMsg: "There was an error uninstalling telemetry updates.\n");
            File.Delete(batPath);
        }
コード例 #11
0
        private void RestoreAppsCmd_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            StackPanelBtns.IsEnabled = false;
            string psPath = Path.Combine(Path.GetTempPath(), "Win_Apps_Worker.ps1");

            try
            {
                using (StreamWriter fText = File.CreateText(psPath))
                {
                    string restoreApps =
                        $@"Get-AppXPackage -AllUsers | Foreach {{Add-AppxPackage -DisableDevelopmentMode -Register ""$($_.InstallLocation)\AppXManifest.xml""}}";
                    fText.WriteLine(restoreApps);
                }

                CustomProc.StartProc("powershell.exe", "\"{ Set-ExecutionPolicy Bypass }; clear; & '" + psPath + "'\"");
                File.Delete(psPath);
            }
            finally
            {
                StackPanelBtns.IsEnabled = true;
            }
        }
コード例 #12
0
        private static bool Uninstall(string uninstallPath, bool isMsi)
        {
            int separatorIndex = uninstallPath.IndexOf(".exe", StringComparison.Ordinal);

            if (separatorIndex < 1)
            {
                return(false);
            }
            string arg = uninstallPath.Substring(separatorIndex + 4);

            uninstallPath = uninstallPath.Substring(0, separatorIndex + 4);
            if (isMsi)
            {
                arg = arg.Replace("/I", "/X");
            }
            if (!File.Exists(uninstallPath) && !isMsi)
            {
                return(true);
            }
            int exitCode = CustomProc.StartProc(uninstallPath, arg);

            return((!isMsi || exitCode == 0) && !File.Exists(uninstallPath));
        }