Skip to content

Portable Tool for an Ideal Windows Setup

fix name retrieval, add task folder processing, & improve Edge auto-start registry deletion

Greedeks3397b329d9be
diff --git a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs
index 001d1b01..4a902c7b 100644
--- a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs
+++ b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
@@ -95,15 +96,7 @@ namespace GTweak.Utilities.Managers
if (existingTasks.Length != 0)
{
- using Microsoft.Win32.TaskScheduler.TaskService taskService = new Microsoft.Win32.TaskScheduler.TaskService();
- foreach (string taskname in existingTasks)
- {
- Microsoft.Win32.TaskScheduler.Task task = taskService.GetTask(taskname);
- if (task != null)
- {
- taskService.RootFolder.DeleteTask(taskname);
- }
- }
+ CommandExecutor.RunCommand("/c " + CommandExecutor.CleanCommand(string.Join(" & ", existingTasks.Select(task => $"schtasks /delete /tn \"{task}\" /f"))));
}
});
}
@@ -112,20 +105,42 @@ namespace GTweak.Utilities.Managers
{
string[] files = Directory.GetFiles(PathLocator.Folders.Tasks, "*", SearchOption.AllDirectories);
- List<string> matches = files.Where(path => string.Equals(Path.GetFileName(path), partialName, StringComparison.OrdinalIgnoreCase)).ToList();
+ List<string> matches = files.Where(path => Path.GetFileName(path).StartsWith(partialName, StringComparison.OrdinalIgnoreCase)).ToList();
if (matches.Count != 0)
{
- string matchPath = matches[0];
-
- string relativePath = matchPath.Substring(PathLocator.Folders.Tasks.Length).Replace(Path.DirectorySeparatorChar, '\\');
+ string relativePath = matches[0].Substring(PathLocator.Folders.Tasks.Length).Replace(Path.DirectorySeparatorChar, '\\');
+ relativePath = Regex.Replace(relativePath, @"^\\+", "");
- return relativePath.StartsWith("\\") ? relativePath : "\\" + relativePath;
+ return $@"\{relativePath}";
}
- return partialName;
+ return $@"\{partialName}*";
}
+ internal static string[] GetAllTasksInPaths(params string[] basePaths)
+ {
+ List<string> taskList = new List<string>();
+
+ foreach (var basePath in basePaths)
+ {
+ string fullBasePath = Path.Combine(PathLocator.Folders.Tasks, basePath.TrimStart('\\'));
+
+ if (Directory.Exists(fullBasePath))
+ {
+ string[] files = Directory.GetFiles(fullBasePath, "*", SearchOption.AllDirectories);
+
+ foreach (string file in files)
+ {
+ string relativePath = file.Substring(PathLocator.Folders.Tasks.Length).Replace(Path.DirectorySeparatorChar, '\\');
+ relativePath = Regex.Replace(relativePath, @"^\\+", "");
+ taskList.Add(@"\" + relativePath);
+ }
+ }
+ }
+
+ return taskList.ToArray();
+ }
private static string[] GetExistingTasks(params string[] tasklist)
{
diff --git a/.Source/GTweak/Utilities/Storage/TaskStorage.cs b/.Source/GTweak/Utilities/Storage/TaskStorage.cs
index 5158d061..b5adde97 100644
--- a/.Source/GTweak/Utilities/Storage/TaskStorage.cs
+++ b/.Source/GTweak/Utilities/Storage/TaskStorage.cs
@@ -1,3 +1,4 @@
+using System.Linq;
using GTweak.Utilities.Managers;
namespace GTweak.Utilities.Storage
@@ -46,9 +47,7 @@ namespace GTweak.Utilities.Storage
@"\Microsoft\Windows\Feedback\Siuf\DmClient",
@"\Microsoft\Windows\Feedback\Siuf\DmClientOnScenarioDownload" };
- protected static readonly string[] speechTasks = {
- @"\Microsoft\Windows\Speech\SpeechModelDownloadTask",
- @"\Microsoft\Windows\Speech\SpeechModelUpdateTask" };
+ protected static readonly string[] speechTasks = TaskSchedulerManager.GetAllTasksInPaths(@"\Microsoft\Windows\Speech\");
protected static readonly string[] nvidiaTasks = {
@"\NvTmRepOnLogon_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}",
@@ -89,17 +88,15 @@ namespace GTweak.Utilities.Storage
protected static readonly string bluetoothTask = @"\Microsoft\Windows\Bluetooth\UninstallDeviceTask";
- protected static readonly string[] oneDriveTask = {
- @"\Microsoft\Windows\OneDrive\OneDrive Standalone Update Task",
- TaskSchedulerManager.GetTaskFullPath("OneDrive Startup") };
+ protected static readonly string[] oneDriveTask = new[] {
+ TaskSchedulerManager.GetTaskFullPath("OneDrive Reporting"),
+ TaskSchedulerManager.GetTaskFullPath("OneDrive Standalone Update"),
+ TaskSchedulerManager.GetTaskFullPath("OneDrive Startup")}
+ .Concat(TaskSchedulerManager.GetAllTasksInPaths(@"\Microsoft\Windows\OneDrive\")).ToArray();
- protected static readonly string[] retailTasks = {
- @"\Microsoft\Windows\RetailDemo\CleanupOfflineContent",
- @"\Microsoft\Windows\RetailDemo\Retail Demo System Agent",
- @"\Microsoft\Windows\RetailDemo\Retail Demo System Agent",
- @"\Microsoft\Windows\RetailDemo\Desktop Retail Demo Idle Detector" };
+ protected static readonly string[] retailTasks = TaskSchedulerManager.GetAllTasksInPaths(@"\Microsoft\Windows\RetailDemo\", @"\Microsoft\Windows\Retail Demo\");
- protected static readonly string[] edgeTasks = {
+ public static readonly string[] edgeTasks = {
TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskMachineUA"),
TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskMachineCore"),
TaskSchedulerManager.GetTaskFullPath("MicrosoftEdgeUpdateTaskUser")};
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index 2d83d77b..707121c5 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -259,8 +259,6 @@ namespace GTweak.Utilities.Tweaks
string[] processes = { "msedge", "edge", "edgeupdate", "edgeupdatem", "msedgewebview2", "microsoftedgeupdate", "msedgewebviewhost", "msedgeuserbroker", "usocoreworker", "widgets", "microsoftedgesh", "microsoftedgecp", "microsoftedge" };
CommandExecutor.RunCommandAsTrustedInstaller("/c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));
- RemoveTasks(edgeTasks);
-
CommandExecutor.RunCommand("/c " + CommandExecutor.CleanCommand(string.Join(" & ", new[]
{
@"rmdir /s /q ""%LocalAppData%\Microsoft\Edge""",
@@ -289,14 +287,36 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate", true);
RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"AppID\MicrosoftEdgeUpdate.exe", true);
RegistryHelp.DeleteFolderTree(Registry.CurrentUser, @"Software\Microsoft\EdgeUpdate", true);
- RegistryHelp.DeleteValue(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Run", "MicrosoftEdgeAutoLaunch_03AF54719E0271FA0A92D5F15CBA10EA");
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\EdgeWebView", true);
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Microsoft\EdgeWebView", true);
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView", true);
RegistryHelp.DeleteFolderTree(Registry.CurrentUser, @"Software\Microsoft\EdgeWebView", true);
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\MicrosoftEdgeElevationService", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects", true);
+
+ foreach (var path in new[] { @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" })
+ {
+ try
+ {
+ using RegistryKey key = Registry.CurrentUser.OpenSubKey(path, writable: true);
+ if (key != null)
+ {
+ foreach (var valueName in key.GetValueNames())
+ {
+ if (valueName.Contains("MicrosoftEdgeAutoLaunch"))
+ {
+ RegistryHelp.DeleteValue(Registry.CurrentUser, path, valueName);
+ }
+ }
+ }
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ }
}
+ RemoveTasks(edgeTasks);
+
static void RemoveDirectory(string path)
{
CommandExecutor.RunCommandAsTrustedInstaller($@"/c takeown /f ""{path}"" /r /d y && icacls ""{path}"" /inheritance:r && icacls ""{path}"" /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 && icacls ""{path}"" /grant {Environment.UserName}:F /t && rd /s /q ""{path}""");