Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix onedrive setup path resolution & removal process
Greedeks239c93dbf629
diff --git a/.Source/GTweak/Core/ViewModel/AddonsViewModel.cs b/.Source/GTweak/Core/ViewModel/AddonsViewModel.csindex f0514f23..0772267e 100644--- a/.Source/GTweak/Core/ViewModel/AddonsViewModel.cs+++ b/.Source/GTweak/Core/ViewModel/AddonsViewModel.cs@@ -112,7 +112,7 @@ namespace GTweak.Core.ViewModelbreak;}- Task.Run(() => { CommandExecutor.RunProcessVisible(fileName, CommandExecutor.CleanCommand(arguments), addon.RequiresElevation); });+ _ = Task.Run(() => CommandExecutor.InvokeRunVisibleProcess(fileName, CommandExecutor.CleanCommand(arguments), addon.RequiresElevation));}catch (Exception ex) { ErrorLogger.LogDebug(ex); }}diff --git a/.Source/GTweak/Modules/Common/PathTargets.cs b/.Source/GTweak/Modules/Common/PathTargets.csindex 9461824a..a153718e 100644--- a/.Source/GTweak/Modules/Common/PathTargets.cs+++ b/.Source/GTweak/Modules/Common/PathTargets.cs@@ -2,6 +2,7 @@ using System;using System.Collections.Concurrent;using System.Collections.Generic;using System.IO;+using GTweak.Modules.Helpers;namespace GTweak.Modules.Common{@@ -11,6 +12,13 @@ namespace GTweak.Modules.Common{internal const string SubKey = @"Software\GTweak";internal static readonly string BaseKey = @$"HKEY_CURRENT_USER\{SubKey}";++ internal static readonly (string Key, string Value)[] OneDriveSetupKeys =+ {+ (@"HKEY_CURRENT_USER\Software\Microsoft\OneDrive", "OneDriveTrigger"),+ (@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OneDriveSetup.exe", "UninstallString"),+ (@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OneDriveSetup.exe", "UninstallString"),+ };}internal static class Links@@ -53,7 +61,7 @@ namespace GTweak.Modules.Commoninternal static string SourceForgeBest(string projectName) => $"https://sourceforge.net/projects/{projectName}/best_release.json";- internal static string SourceForgeRss(string projectName) => $"https://sourceforge.net/projects/{projectName}/rss?path=/";+ internal static string SourceForgeRss(string projectName) => $"https://sourceforge.net/projects/{projectName}/rss?root=/";internal static string SourceForgeFile(string projectName, string filePath) => $"https://downloads.sourceforge.net/project/{projectName}/{filePath}";@@ -301,7 +309,47 @@ namespace GTweak.Modules.Commoninternal static readonly string Explorer = FindExecutablePath("explorer.exe");- internal static readonly string OneDriveSetup = FindExecutablePath("onedrivesetup.exe");+ internal static string OneDriveSetup+ {+ get+ {+ foreach (var (key, value) in Registry.OneDriveSetupKeys)+ {+ string path = RegistryHelper.GetValue<string>(key, value, null);+ if (string.IsNullOrEmpty(path))+ {+ continue;+ }++ path = value == "OneDriveTrigger" ? Path.Combine(Path.GetDirectoryName(path), "OneDriveSetup.exe") : path.Split(new[] { " /" }, StringSplitOptions.None)[0].Trim('"');++ if (File.Exists(path))+ {+ return path;+ }+ }++ foreach (string instance in OneDriveInstances)+ {+ string root = Path.GetDirectoryName(instance);+ if (!Directory.Exists(root))+ {+ continue;+ }++ foreach (string dir in Directory.GetDirectories(root))+ {+ string setup = Path.Combine(dir, "OneDriveSetup.exe");+ if (File.Exists(setup))+ {+ return setup;+ }+ }+ }++ return string.Empty;+ }+ }internal static string EdgeSetup{diff --git a/.Source/GTweak/Modules/Helpers/CommandExecutor.cs b/.Source/GTweak/Modules/Helpers/CommandExecutor.csindex 652cd648..d454f26c 100644--- a/.Source/GTweak/Modules/Helpers/CommandExecutor.cs+++ b/.Source/GTweak/Modules/Helpers/CommandExecutor.cs@@ -68,7 +68,7 @@ namespace GTweak.Modules.Helperscatch (Exception ex) { ErrorLogger.LogDebug(ex); }}- internal static async void RunProcessVisible(string fileName, string arguments = "", bool isElevationRequired = false)+ internal static async Task InvokeRunVisibleProcess(string fileName, string arguments = "", bool isElevationRequired = false){if (isElevationRequired){@@ -87,7 +87,11 @@ namespace GTweak.Modules.Helpers};using Process process = new Process { StartInfo = startInfo };- try { process.Start(); }+ try+ {+ process.Start();+ await process.WaitForExitAsync().ConfigureAwait(false);+ }catch (Exception ex) { ErrorLogger.LogDebug(ex); }}diff --git a/.Source/GTweak/Modules/Tweaks/AppxPackageHandler.cs b/.Source/GTweak/Modules/Tweaks/AppxPackageHandler.csindex df3e8e83..f3e0b18a 100644--- a/.Source/GTweak/Modules/Tweaks/AppxPackageHandler.cs+++ b/.Source/GTweak/Modules/Tweaks/AppxPackageHandler.cs@@ -87,7 +87,7 @@ namespace GTweak.Modules.Tweaksinternal static async Task RestoreOneDriveFolder(){- await CommandExecutor.InvokeRunCommand($@"/c {PathTargets.Executable.OneDriveSetup}").ConfigureAwait(false);+ await CommandExecutor.InvokeRunVisibleProcess(PathTargets.Executable.OneDriveSetup).ConfigureAwait(false);SetTaskState(true, oneDriveTask);@@ -99,16 +99,10 @@ namespace GTweak.Modules.Tweaks{if (packageName == "OneDrive"){- await CommandExecutor.InvokeRunCommand($@"/c taskkill /f /im OneDrive.exe & {PathTargets.Executable.OneDriveSetup} /uninstall").ConfigureAwait(false);-- RegistryHelper.DeleteFolderTree(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");- RegistryHelper.DeleteFolderTree(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");-- SetTaskState(false, oneDriveTask);-- CommandExecutor.RunCommand($@"/c rd /s /q %userprofile%\AppData\Local\Microsoft\OneDrive & rd /s /q %userprofile%\AppData\Local\OneDrive &- rd /s /q ""%allusersprofile%\Microsoft OneDrive"" & rd /s /q {PathTargets.Folders.SystemDrive}OneDriveTemp{(_isLocalAccount ? @" & rd /s /q %userprofile%\OneDrive" : "")}");-+ await CommandExecutor.InvokeRunCommand($@"/c taskkill /f /im OneDrive.exe & taskkill /f /im FileCoAuth.exe").ConfigureAwait(false);+ await Task.Run(() => CommandExecutor.RunCommandAsTrustedInstaller($@"/c ""{PathTargets.Executable.OneDriveSetup}"" /uninstall /allusers")).ConfigureAwait(false);+ await Task.Delay(3000).ConfigureAwait(false);+ PostRemoveOneDrive();return;}@@ -185,6 +179,17 @@ namespace GTweak.Modules.Tweaks}}+ private static void PostRemoveOneDrive()+ {+ RegistryHelper.DeleteFolderTree(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");+ RegistryHelper.DeleteFolderTree(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");++ SetTaskState(false, oneDriveTask);++ CommandExecutor.RunCommand($@"/c rd /s /q %userprofile%\AppData\Local\Microsoft\OneDrive & rd /s /q %userprofile%\AppData\Local\OneDrive &+ rd /s /q ""%allusersprofile%\Microsoft OneDrive"" & rd /s /q {PathTargets.Folders.SystemDrive}OneDriveTemp{(_isLocalAccount ? @" & rd /s /q %userprofile%\OneDrive" : "")}");+ }+private static void PostRemoveWidgets() => RegistryHelper.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Dsh", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);private static void PostRemoveDevHome() => RegistryHelper.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\DevHomeUpdate");