Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
upd. optimize scheduled task state checks & re
Greedeks01ce42b80d6d
diff --git a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.csindex 4fb55dd4..908718be 100644--- a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs+++ b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs@@ -86,10 +86,7 @@ namespace GTweak.Utilities.Configurationreturn bmp;}}- catch (Exception ex)- {- ErrorLogging.LogDebug(ex);- }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }return (ImageSource)Application.Current.Resources["Icon_ProfileAvatar"];}diff --git a/.Source/GTweak/Utilities/Controls/PathLocator.cs b/.Source/GTweak/Utilities/Controls/PathLocator.csindex 03654003..83e45fe2 100644--- a/.Source/GTweak/Utilities/Controls/PathLocator.cs+++ b/.Source/GTweak/Utilities/Controls/PathLocator.cs@@ -122,10 +122,7 @@ namespace GTweak.Utilities.Controlsreturn candidateRel;}}- catch (Exception ex)- {- ErrorLogging.LogDebug(ex);- }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }}}@@ -179,10 +176,7 @@ namespace GTweak.Utilities.Controlsbreak;}}- catch (Exception ex)- {- ErrorLogging.LogDebug(ex);- }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }}if (found)@@ -190,10 +184,7 @@ namespace GTweak.Utilities.Controlsbreak;}}- catch (Exception ex)- {- ErrorLogging.LogDebug(ex);- }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }}if (found)diff --git a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs b/.Source/GTweak/Utilities/Helpers/CommandExecutor.csindex 52e77d75..e53d3ee1 100644--- a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs+++ b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs@@ -15,41 +15,35 @@ namespace GTweak.Utilities.Helpersinternal static async Task<string> GetCommandOutput(string command, bool isPowerShell = true){- return await Task.Run(async () =>+ ProcessStartInfo startInfo = new ProcessStartInfo{- ProcessStartInfo startInfo = new ProcessStartInfo- {- FileName = isPowerShell ? PathLocator.Executable.PowerShell : PathLocator.Executable.CommandShell,- Arguments = isPowerShell ? $"-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command \"{command}\"" : command,- WindowStyle = ProcessWindowStyle.Hidden,- RedirectStandardOutput = true,- RedirectStandardError = true,- UseShellExecute = false,- CreateNoWindow = true,- StandardOutputEncoding = Encoding.UTF8,- StandardErrorEncoding = Encoding.UTF8,- WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)- };+ FileName = isPowerShell ? PathLocator.Executable.PowerShell : PathLocator.Executable.CommandShell,+ Arguments = isPowerShell ? $"-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command \"{command}\"" : command,+ WindowStyle = ProcessWindowStyle.Hidden,+ RedirectStandardOutput = true,+ RedirectStandardError = true,+ UseShellExecute = false,+ CreateNoWindow = true,+ StandardOutputEncoding = Encoding.UTF8,+ StandardErrorEncoding = Encoding.UTF8,+ WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)+ };- using Process process = new Process { StartInfo = startInfo };- try { process.Start(); }- catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ using Process process = new Process { StartInfo = startInfo };+ try { process.Start(); }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }- string output = process.StandardOutput.ReadToEnd();- string error = process.StandardError.ReadToEnd();+ string output = process.StandardOutput.ReadToEnd();+ string error = process.StandardError.ReadToEnd();- await process.WaitForExitAsync().ConfigureAwait(false);+ await process.WaitForExitAsync().ConfigureAwait(false);- if (process.ExitCode == 0)- {- return string.Join(Environment.NewLine, output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));- }- else- {- Debug.WriteLine($"{process.ExitCode}: {error}");- return string.Empty;- }- });+ if (process.ExitCode == 0)+ {+ return string.Join(Environment.NewLine, output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));+ }++ return string.Empty;}internal static void RunCommandAsTrustedInstaller(string command, bool isPowerShell = false) =>@@ -148,7 +142,6 @@ namespace GTweak.Utilities.Helpersreturn Task.CompletedTask;}-internal static string CleanCommand(string rawCommand){if (string.IsNullOrWhiteSpace(rawCommand))diff --git a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.csindex 4c9921b0..001d1b01 100644--- a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs+++ b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs@@ -15,18 +15,38 @@ namespace GTweak.Utilities.Managers{if (tasklist != null && tasklist.Length != 0){- using Microsoft.Win32.TaskScheduler.TaskService taskService = new Microsoft.Win32.TaskScheduler.TaskService();+ bool isEnabledFound = false;- foreach (var taskName in tasklist)+ Parallel.ForEach(tasklist, () => new Microsoft.Win32.TaskScheduler.TaskService(),+ (taskName, loopState, taskScheduler) =>{- Microsoft.Win32.TaskScheduler.Task task = taskService.GetTask(taskName);- if (task != null && task.Enabled)+ try{- return true;+ if (isEnabledFound)+ {+ loopState.Stop();+ return taskScheduler;+ }++ Microsoft.Win32.TaskScheduler.Task scheduledTask = taskScheduler.GetTask(taskName);++ if (scheduledTask != null && scheduledTask.Enabled)+ {+ isEnabledFound = true;+ loopState.Stop();+ }}- }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }++ return taskScheduler;+ },+ taskScheduler =>+ {+ try { taskScheduler.Dispose(); }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ });- return false;+ return isEnabledFound;}return false;diff --git a/.Source/GTweak/Windows/ImportWindow.xaml.cs b/.Source/GTweak/Windows/ImportWindow.xaml.csindex d6824dce..42c4667d 100644--- a/.Source/GTweak/Windows/ImportWindow.xaml.cs+++ b/.Source/GTweak/Windows/ImportWindow.xaml.cs@@ -158,10 +158,7 @@ namespace GTweak.Windows}}}- catch (Exception ex)- {- ErrorLogging.LogDebug(ex);- }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }appliedTweaks++;progress.Report((byte)((double)appliedTweaks / totalTweaks * 100));