Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix scheduled tasks not being disabled due to incorrect path resolution
Greedeks4ba313fd6449
diff --git a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.csindex 1139c4f1..a108b8cf 100644--- a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs+++ b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs@@ -66,10 +66,10 @@ namespace GTweak.Utilities.ManagersTask.Run(() =>{string[] existingTasks = GetExistingTasks(tasklist);+if (existingTasks.Length != 0){- IEnumerable<string> commands = existingTasks.Select(task => $"schtasks /change {(state ? "/enable" : "/disable")} /tn \"{task.Replace("\"", "\\\"")}\"");- CommandExecutor.RunCommandAsTrustedInstaller($"/c {string.Join(" & ", commands)}");+ CommandExecutor.RunCommandAsTrustedInstaller("/c " + CommandExecutor.CleanCommand(string.Join(" & ", existingTasks.Select(task => $"schtasks /change {(state ? "/enable" : "/disable")} /tn \"{task}\""))));}});}@@ -98,18 +98,22 @@ namespace GTweak.Utilities.Managersinternal static string GetTaskFullPath(string partialName){string[] files = Directory.GetFiles(PathLocator.Folders.Tasks, "*", SearchOption.AllDirectories);- string matchPath = files.FirstOrDefault(path => Path.GetFileName(path).IndexOf(partialName, StringComparison.OrdinalIgnoreCase) >= 0);- if (!string.IsNullOrWhiteSpace(matchPath))- {- return Path.GetFileName(matchPath);- }- else+ List<string> matches = files.Where(path => string.Equals(Path.GetFileName(path), partialName, StringComparison.OrdinalIgnoreCase)).ToList();++ if (matches.Count != 0){- return partialName;+ string matchPath = matches[0];++ string relativePath = matchPath.Substring(PathLocator.Folders.Tasks.Length).Replace(Path.DirectorySeparatorChar, '\\');++ return relativePath.StartsWith("\\") ? relativePath : "\\" + relativePath;}++ return partialName;}+private static string[] GetExistingTasks(params string[] tasklist){List<string> foundExisting = new List<string>(tasklist.Length);diff --git a/.Source/GTweak/Utilities/Storage/TaskStorage.cs b/.Source/GTweak/Utilities/Storage/TaskStorage.csindex 9862d868..a1abce5d 100644--- a/.Source/GTweak/Utilities/Storage/TaskStorage.cs+++ b/.Source/GTweak/Utilities/Storage/TaskStorage.cs@@ -1,4 +1,4 @@-using GTweak.Utilities.Managers;+using GTweak.Utilities.Managers;namespace GTweak.Utilities.Storage{@@ -64,12 +64,12 @@ namespace GTweak.Utilities.Storageprotected static readonly string[] oneDriveTask = {@"\Microsoft\Windows\OneDrive\OneDrive Standalone Update Task",- $@"\{TaskSchedulerManager.GetTaskFullPath("OneDrive Startup")}" };+ TaskSchedulerManager.GetTaskFullPath("OneDrive Startup") };protected static readonly string[] edgeTasks = {- $@"\{TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskMachineUA")}",- $@"\{TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskMachineCore")}",- $@"\{TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskUser")}" };+ TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskMachineUA"),+ TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskMachineCore"),+ TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskUser")};protected static readonly string[] winDefenderTasks = {@"\Microsoft\Windows\ExploitGuard\ExploitGuard MDM policy Refresh",