Skip to content

Portable Tool for an Ideal Windows Setup

upd. PackagesDetails structure and fix OneDrive detection deb v5.4.2

Greedeks97013d43c138
diff --git a/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs b/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs
index 4457a718..99416210 100644
--- a/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
@@ -45,12 +46,12 @@ namespace GTweak.Core.ViewModel
foreach (var kv in UninstallingPakages.PackagesDetails)
{
string name = kv.Key;
- var (_, IsUnavailable, _) = kv.Value;
+ UninstallingPakages.PackagesInfo details = kv.Value;
PakagesModel pkg = new PakagesModel
{
Name = name,
- IsUnavailable = !IsUnavailable
+ IsUnavailable = !details.IsUnavailable
};
UpdatePackageState(pkg);
@@ -62,13 +63,21 @@ namespace GTweak.Core.ViewModel
{
if (item != null && !string.IsNullOrEmpty(item.Name))
{
- if ((UninstallingPakages.PackagesDetails?.TryGetValue(item.Name, out var val)) == true)
+ if (UninstallingPakages.PackagesDetails != null && UninstallingPakages.PackagesDetails.TryGetValue(item.Name, out UninstallingPakages.PackagesInfo val) && val != null)
{
item.IsUnavailable = !val.IsUnavailable;
if (!string.Equals(item?.Name, "OneDrive", StringComparison.OrdinalIgnoreCase))
{
- item.Installed = val.Scripts != null && val.Scripts.Any() && val.Scripts.Any(pattern => UninstallingPakages.InstalledPackagesCache.Any(pkg => Regex.IsMatch(pkg, $"^{Regex.Escape(pattern)}", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)));
+ IReadOnlyList<string> scripts = val.Scripts;
+ if (scripts != null && scripts?.Count > 0)
+ {
+ item.Installed = scripts.Any(pattern => UninstallingPakages.InstalledPackagesCache.Any(pkg => Regex.IsMatch(pkg, $"^{Regex.Escape(pattern)}", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)));
+ }
+ else
+ {
+ item.Installed = false;
+ }
}
else
{
diff --git a/.Source/GTweak/Properties/AssemblyInfo.cs b/.Source/GTweak/Properties/AssemblyInfo.cs
index 3600f3bb..c12ccf9b 100644
--- a/.Source/GTweak/Properties/AssemblyInfo.cs
+++ b/.Source/GTweak/Properties/AssemblyInfo.cs
@@ -7,9 +7,9 @@ using System.Windows;
[assembly: AssemblyProduct("GTweak")]
[assembly: AssemblyCopyright("� 2024-2026 Greedeks")]
[assembly: AssemblyTrademark("Greedeks")]
-[assembly: AssemblyInformationalVersion("Build: 5.4.1")]
-[assembly: AssemblyVersion("5.4.45.64")]
-[assembly: AssemblyFileVersion("5.4.45.64")]
+[assembly: AssemblyInformationalVersion("Build: 5.4.2")]
+[assembly: AssemblyVersion("5.4.31.921")]
+[assembly: AssemblyFileVersion("5.4.31.921")]
[assembly: ComVisible(false)]
diff --git a/.Source/GTweak/Properties/AssemblyInfo.tt b/.Source/GTweak/Properties/AssemblyInfo.tt
index 2d722ced..4053991d 100644
--- a/.Source/GTweak/Properties/AssemblyInfo.tt
+++ b/.Source/GTweak/Properties/AssemblyInfo.tt
@@ -22,7 +22,7 @@ using System.Windows;
[assembly: AssemblyMetadata("RepositoryType", "git")]
<#+
- private const string majorVersion = "Build: 5.4.1";
+ private const string majorVersion = "Build: 5.4.2";
private string GenerateVersion()
{
diff --git a/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs b/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs
index 43545c0d..e903fd99 100644
--- a/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs
+++ b/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Threading;
using System.Threading.Tasks;
@@ -8,6 +8,7 @@ namespace GTweak.Utilities.Helpers
{
private Task _previousTask = Task.FromResult(true);
private readonly object _key = new object();
+
internal Task QueueTask(Action action)
{
lock (_key)
diff --git a/.Source/GTweak/Utilities/Storage/WinKeyStorage.cs b/.Source/GTweak/Utilities/Storage/WinKeyStorage.cs
index 65efa098..8d1f42f9 100644
--- a/.Source/GTweak/Utilities/Storage/WinKeyStorage.cs
+++ b/.Source/GTweak/Utilities/Storage/WinKeyStorage.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace GTweak.Utilities.Storage
{
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index 51915769..c07e7a5c 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using GTweak.Utilities.Controls;
@@ -13,11 +14,82 @@ namespace GTweak.Utilities.Tweaks
{
internal sealed class UninstallingPakages : TaskSchedulerManager
{
+ private static bool _isLocalAccount = false;
+
internal static event Action DataChanged;
internal static void OnPackagesChanged() => DataChanged?.Invoke();
- internal static bool IsOneDriveInstalled => File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "OneDrive", "OneDrive.exe"));
- private static bool _isLocalAccount = false;
+ internal sealed class PackagesInfo
+ {
+ internal string Alias { get; }
+ internal bool IsUnavailable { get; set; }
+ internal IReadOnlyList<string> Scripts { get; }
+
+ internal PackagesInfo(string alias = null, IReadOnlyList<string> scripts = null)
+ {
+ Alias = alias;
+ Scripts = scripts;
+ }
+ }
+
+ internal static bool IsOneDriveInstalled => File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "OneDrive", "OneDrive.exe")) ||
+ File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Microsoft OneDrive", "OneDrive.exe")) || File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft OneDrive", "OneDrive.exe"));
+
+ internal static readonly Dictionary<string, PackagesInfo> PackagesDetails = new Dictionary<string, PackagesInfo>(StringComparer.OrdinalIgnoreCase)
+ {
+ ["OneDrive"] = new PackagesInfo(),
+ ["MicrosoftStore"] = new PackagesInfo(scripts: new[] { "Microsoft.WindowsStore" }),
+ ["Todos"] = new PackagesInfo("TodoList", new[] { "Microsoft.Todos", "Microsoft.ToDo" }),
+ ["BingWeather"] = new PackagesInfo("MSWeather", new[] { "Microsoft.BingWeather" }),
+ ["Microsoft3D"] = new PackagesInfo("3DViewer", new[] { "Microsoft.Microsoft3DViewer" }),
+ ["Music"] = new PackagesInfo("zunemusic", new[] { "Microsoft.ZuneMusic", "Microsoft.GrooveMusic" }),
+ ["GetHelp"] = new PackagesInfo(scripts: new[] { "Microsoft.GetHelp" }),
+ ["MicrosoftOfficeHub"] = new PackagesInfo("officehub", new[] { "Microsoft.MicrosoftOfficeHub" }),
+ ["MicrosoftSolitaireCollection"] = new PackagesInfo("solitaire", new[] { "Microsoft.MicrosoftSolitaireCollection" }),
+ ["MixedReality"] = new PackagesInfo("MixedRealityPortal", new[] { "Microsoft.MixedReality.Portal" }),
+ ["Xbox"] = new PackagesInfo(scripts: new[] { "Microsoft.XboxApp", "Microsoft.GamingApp", "Microsoft.XboxGamingOverlay", "Microsoft.XboxGameOverlay", "Microsoft.XboxIdentityProvider", "Microsoft.Xbox.TCUI", "Microsoft.XboxSpeechToTextOverlay" }),
+ ["Paint3D"] = new PackagesInfo(scripts: new[] { "Microsoft.MSPaint" }),
+ ["OneNote"] = new PackagesInfo("MSOneNote", new[] { "Microsoft.Office.OneNote", "Microsoft.OneNote" }),
+ ["People"] = new PackagesInfo(scripts: new[] { "Microsoft.People" }),
+ ["MicrosoftStickyNotes"] = new PackagesInfo("MSStickyNotes", new[] { "Microsoft.MicrosoftStickyNotes" }),
+ ["Widgets"] = new PackagesInfo("Windows.Client.WebExperience", new[] { "MicrosoftWindows.Client.WebExperience", "Microsoft.WidgetsPlatformRuntime", "Windows.Client.WebExperience" }),
+ ["ScreenSketch"] = new PackagesInfo(scripts: new[] { "Microsoft.ScreenSketch" }),
+ ["Phone"] = new PackagesInfo("PhoneLink", new[] { "Microsoft.YourPhone", "MicrosoftWindows.CrossDevice" }),
+ ["Photos"] = new PackagesInfo("MSPhotos", new[] { "Microsoft.Windows.Photos" }),
+ ["FeedbackHub"] = new PackagesInfo("feedback", new[] { "Microsoft.WindowsFeedbackHub" }),
+ ["SoundRecorder"] = new PackagesInfo(scripts: new[] { "Microsoft.WindowsSoundRecorder" }),
+ ["Alarms"] = new PackagesInfo(scripts: new[] { "Microsoft.WindowsAlarms" }),
+ ["SkypeApp"] = new PackagesInfo("Skype", new[] { "Microsoft.SkypeApp" }),
+ ["Maps"] = new PackagesInfo(scripts: new[] { "Microsoft.WindowsMaps" }),
+ ["Camera"] = new PackagesInfo(scripts: new[] { "Microsoft.WindowsCamera" }),
+ ["Video"] = new PackagesInfo("zunevideo", new[] { "Microsoft.ZuneVideo" }),
+ ["BingNews"] = new PackagesInfo(scripts: new[] { "Microsoft.BingNews" }),
+ ["Mail"] = new PackagesInfo("communicationsapps", new[] { "microsoft.windowscommunicationsapps" }),
+ ["MicrosoftTeams"] = new PackagesInfo("Teams", new[] { "MicrosoftTeams", "MSTeams" }),
+ ["PowerAutomateDesktop"] = new PackagesInfo(scripts: new[] { "Microsoft.PowerAutomateDesktop" }),
+ ["Cortana"] = new PackagesInfo(scripts: new[] { "Microsoft.549981C3F5F10" }),
+ ["ClipChamp"] = new PackagesInfo("Clipchamp Video Editor", new[] { "Clipchamp.Clipchamp" }),
+ ["GetStarted"] = new PackagesInfo(scripts: new[] { "Microsoft.Getstarted" }),
+ ["BingSports"] = new PackagesInfo(scripts: new[] { "Microsoft.BingSports" }),
+ ["BingFinance"] = new PackagesInfo(scripts: new[] { "Microsoft.BingFinance" }),
+ ["MicrosoftFamily"] = new PackagesInfo("FamilySafety", new[] { "MicrosoftCorporationII.MicrosoftFamily" }),
+ ["BingSearch"] = new PackagesInfo(scripts: new[] { "Microsoft.BingSearch" }),
+ ["Outlook"] = new PackagesInfo(scripts: new[] { "Microsoft.OutlookForWindows" }),
+ ["QuickAssist"] = new PackagesInfo(scripts: new[] { "MicrosoftCorporationII.QuickAssist" }),
+ ["DevHome"] = new PackagesInfo(scripts: new[] { "Microsoft.Windows.DevHome" }),
+ ["WindowsTerminal"] = new PackagesInfo(scripts: new[] { "Microsoft.WindowsTerminal" }),
+ ["LinkedIn"] = new PackagesInfo("LinkedInforWindows", new[] { "Microsoft.LinkedIn" }),
+ ["WebMediaExtensions"] = new PackagesInfo(scripts: new[] { "Microsoft.WebMediaExtensions" }),
+ ["OneConnect"] = new PackagesInfo("MobilePlans", new[] { "Microsoft.OneConnect" }),
+ ["Edge"] = new PackagesInfo("MicrosoftEdge", new[] { "Microsoft.MicrosoftEdge.Stable", "Microsoft.MicrosoftEdge.*", "Microsoft.Copilot" }),
+ ["Notepad"] = new PackagesInfo("Notepad", new[] { "Microsoft.WindowsNotepad" }),
+ ["Calculator"] = new PackagesInfo("Calculator", new[] { "Microsoft.WindowsCalculator" }),
+ ["Copilot"] = new PackagesInfo(scripts: new[] { "Microsoft.Copilot" }),
+ ["WhiteBoard"] = new PackagesInfo(scripts: new[] { "Microsoft.Whiteboard" }),
+ ["Wallet"] = new PackagesInfo("MSPay", new[] { "Microsoft.Wallet" }),
+ ["Spotify"] = new PackagesInfo(scripts: new[] { "SpotifyAB.SpotifyMusic" }),
+ ["WhatsApp"] = new PackagesInfo("WhatsAppDesktop", new[] { "5319275A.WhatsAppDesktop" }),
+ };
internal static HashSet<string> InstalledPackagesCache = new HashSet<string>();
@@ -32,74 +104,19 @@ namespace GTweak.Utilities.Tweaks
finally { OnPackagesChanged(); }
}
- internal static Dictionary<string, (string Alias, bool IsUnavailable, List<string> Scripts)> PackagesDetails = new Dictionary<string, (string Alias, bool IsUnavailable, List<string> Scripts)>()
- {
- ["OneDrive"] = (null, false, null),
- ["MicrosoftStore"] = (null, false, new List<string> { "Microsoft.WindowsStore" }),
- ["Todos"] = ("TodoList", false, new List<string> { "Microsoft.Todos", "Microsoft.ToDo" }),
- ["BingWeather"] = ("MSWeather", false, new List<string> { "Microsoft.BingWeather" }),
- ["Microsoft3D"] = ("3DViewer", false, new List<string> { "Microsoft.Microsoft3DViewer" }),
- ["Music"] = ("zunemusic", false, new List<string> { "Microsoft.ZuneMusic", "Microsoft.GrooveMusic" }),
- ["GetHelp"] = (null, false, new List<string> { "Microsoft.GetHelp" }),
- ["MicrosoftOfficeHub"] = ("officehub", false, new List<string> { "Microsoft.MicrosoftOfficeHub" }),
- ["MicrosoftSolitaireCollection"] = ("solitaire", false, new List<string> { "Microsoft.MicrosoftSolitaireCollection" }),
- ["MixedReality"] = ("MixedRealityPortal", false, new List<string> { "Microsoft.MixedReality.Portal" }),
- ["Xbox"] = (null, false, new List<string> { "Microsoft.XboxApp", "Microsoft.GamingApp", "Microsoft.XboxGamingOverlay", "Microsoft.XboxGameOverlay", "Microsoft.XboxIdentityProvider", "Microsoft.Xbox.TCUI", "Microsoft.XboxSpeechToTextOverlay" }),
- ["Paint3D"] = (null, false, new List<string> { "Microsoft.MSPaint" }),
- ["OneNote"] = ("MSOneNote", false, new List<string> { "Microsoft.Office.OneNote", "Microsoft.OneNote" }),
- ["People"] = (null, false, new List<string> { "Microsoft.People" }),
- ["MicrosoftStickyNotes"] = ("MSStickyNotes", false, new List<string> { "Microsoft.MicrosoftStickyNotes" }),
- ["Widgets"] = ("Windows.Client.WebExperience", false, new List<string> { "MicrosoftWindows.Client.WebExperience", "Microsoft.WidgetsPlatformRuntime", "Windows.Client.WebExperience" }),
- ["ScreenSketch"] = (null, false, new List<string> { "Microsoft.ScreenSketch" }),
- ["Phone"] = ("PhoneLink", false, new List<string> { "Microsoft.YourPhone", "MicrosoftWindows.CrossDevice" }),
- ["Photos"] = ("MSPhotos", false, new List<string> { "Microsoft.Windows.Photos" }),
- ["FeedbackHub"] = ("feedback", false, new List<string> { "Microsoft.WindowsFeedbackHub" }),
- ["SoundRecorder"] = (null, false, new List<string> { "Microsoft.WindowsSoundRecorder" }),
- ["Alarms"] = (null, false, new List<string> { "Microsoft.WindowsAlarms" }),
- ["SkypeApp"] = ("Skype", false, new List<string> { "Microsoft.SkypeApp" }),
- ["Maps"] = (null, false, new List<string> { "Microsoft.WindowsMaps" }),
- ["Camera"] = (null, false, new List<string> { "Microsoft.WindowsCamera" }),
- ["Video"] = ("zunevideo", false, new List<string> { "Microsoft.ZuneVideo" }),
- ["BingNews"] = (null, false, new List<string> { "Microsoft.BingNews" }),
- ["Mail"] = ("communicationsapps", false, new List<string> { "microsoft.windowscommunicationsapps" }),
- ["MicrosoftTeams"] = ("Teams", false, new List<string> { "MicrosoftTeams", "MSTeams" }),
- ["PowerAutomateDesktop"] = (null, false, new List<string> { "Microsoft.PowerAutomateDesktop" }),
- ["Cortana"] = (null, false, new List<string> { "Microsoft.549981C3F5F10" }),
- ["ClipChamp"] = ("Clipchamp Video Editor", false, new List<string> { "Clipchamp.Clipchamp" }),
- ["GetStarted"] = (null, false, new List<string> { "Microsoft.Getstarted" }),
- ["BingSports"] = (null, false, new List<string> { "Microsoft.BingSports" }),
- ["BingFinance"] = (null, false, new List<string> { "Microsoft.BingFinance" }),
- ["MicrosoftFamily"] = ("FamilySafety", false, new List<string> { "MicrosoftCorporationII.MicrosoftFamily" }),
- ["BingSearch"] = (null, false, new List<string> { "Microsoft.BingSearch" }),
- ["Outlook"] = (null, false, new List<string> { "Microsoft.OutlookForWindows" }),
- ["QuickAssist"] = (null, false, new List<string> { "MicrosoftCorporationII.QuickAssist" }),
- ["DevHome"] = (null, false, new List<string> { "Microsoft.Windows.DevHome" }),
- ["WindowsTerminal"] = (null, false, new List<string> { "Microsoft.WindowsTerminal" }),
- ["LinkedIn"] = ("LinkedInforWindows", false, new List<string> { "Microsoft.LinkedIn" }),
- ["WebMediaExtensions"] = (null, false, new List<string> { "Microsoft.WebMediaExtensions" }),
- ["OneConnect"] = ("MobilePlans", false, new List<string> { "Microsoft.OneConnect" }),
- ["Edge"] = ("MicrosoftEdge", false, new List<string> { "Microsoft.MicrosoftEdge.Stable", "Microsoft.MicrosoftEdge.*", "Microsoft.Copilot" }),
- ["Notepad"] = ("Notepad", false, new List<string> { "Microsoft.WindowsNotepad" }),
- ["Calculator"] = ("Calculator", false, new List<string> { "Microsoft.WindowsCalculator" }),
- ["Copilot"] = (null, false, new List<string> { "Microsoft.Copilot" }),
- ["WhiteBoard"] = (null, false, new List<string> { "Microsoft.Whiteboard" }),
- ["Wallet"] = ("MSPay", false, new List<string> { "Microsoft.Wallet" }),
- ["Spotify"] = (null, false, new List<string> { "SpotifyAB.SpotifyMusic" }),
- ["WhatsApp"] = ("WhatsAppDesktop", false, new List<string> { "5319275A.WhatsAppDesktop" }),
- };
-
internal static bool HandleAvailabilityStatus(string key, bool? isUnavailable = null)
{
if (PackagesDetails.TryGetValue(key, out var details))
{
if (isUnavailable.HasValue)
{
- PackagesDetails[key] = (details.Alias, isUnavailable.Value, details.Scripts);
+ details.IsUnavailable = isUnavailable.Value;
}
OnPackagesChanged();
return details.IsUnavailable;
}
+
return false;
}
@@ -116,236 +133,244 @@ namespace GTweak.Utilities.Tweaks
}
}
- internal static Task RestoreOneDriveFolder()
+ internal static async Task RestoreOneDriveFolder()
{
- return Task.Run(async () =>
- {
- await CommandExecutor.InvokeRunCommand($@"/c {PathLocator.Executable.OneDrive}").ConfigureAwait(false);
+ await CommandExecutor.InvokeRunCommand($@"/c {PathLocator.Executable.OneDrive}").ConfigureAwait(false);
- SetTaskState(true, oneDriveTask);
+ SetTaskState(true, oneDriveTask);
- RegistryHelp.CreateFolder(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
- RegistryHelp.CreateFolder(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
- });
+ RegistryHelp.CreateFolder(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
+ RegistryHelp.CreateFolder(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
}
- internal static Task RemoveAppxPackage(string packageName, bool shouldRemoveWebView = false)
+ internal static async Task RemoveAppxPackage(string packageName, bool shouldRemoveWebView = false)
{
if (packageName == "OneDrive")
{
- return Task.Run(async () =>
- {
- await CommandExecutor.InvokeRunCommand($@"/c taskkill /f /im OneDrive.exe & {PathLocator.Executable.OneDrive} /uninstall").ConfigureAwait(false);
+ await CommandExecutor.InvokeRunCommand($@"/c taskkill /f /im OneDrive.exe & {PathLocator.Executable.OneDrive} /uninstall").ConfigureAwait(false);
+
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
+ SetTaskState(false, oneDriveTask);
- 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 {PathLocator.Folders.SystemDrive}OneDriveTemp{(_isLocalAccount ? @" & rd /s /q %userprofile%\OneDrive" : "")}");
- 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 {PathLocator.Folders.SystemDrive}OneDriveTemp{(_isLocalAccount ? @" & rd /s /q %userprofile%\OneDrive" : "")}");
- });
+ return;
}
- return Task.Run(async () =>
+ try
{
- try
+ if (!PackagesDetails.TryGetValue(packageName, out PackagesInfo details))
{
- if (!PackagesDetails.TryGetValue(packageName, out var details))
- {
- ErrorLogging.LogDebug(new InvalidOperationException($"PackageDetails does not contain key '{packageName}'"));
- return;
- }
+ ErrorLogging.LogDebug(new InvalidOperationException($"PackageDetails does not contain key '{packageName}'"));
+ return;
+ }
- string Alias = details.Alias;
- List<string> Scripts = details.Scripts;
+ string Alias = details.Alias;
+ IReadOnlyList<string> scripts = details.Scripts;
- List<string> packageNamesToRemove = new List<string> { packageName };
+ List<string> packageNamesToRemove = new List<string> { packageName };
- if (!string.IsNullOrEmpty(Alias))
- {
- packageNamesToRemove.Add(Alias);
- }
+ if (!string.IsNullOrWhiteSpace(Alias))
+ {
+ packageNamesToRemove.Add(Alias);
+ }
- if (Scripts != null && Scripts.Count > 0)
- {
- packageNamesToRemove.AddRange(Scripts);
- }
+ if (scripts != null && scripts.Count > 0)
+ {
+ packageNamesToRemove.AddRange(scripts);
+ }
+ string psCommands = $@"$pattern = '{string.Join("|", packageNamesToRemove.Select(Regex.Escape))}'
+ Get-AppxPackage -AllUsers | Where-Object {{ $_.Name -match $pattern }} | ForEach-Object {{ Remove-AppxPackage -AllUsers -Package $_.PackageFullName }}
+ Get-AppxProvisionedPackage -Online | Where-Object {{ $_.PackageName -match $pattern }} | ForEach-Object {{ Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName -AllUsers}}";
- List<string> psCommands = packageNamesToRemove.SelectMany(name => new[]
- {
- $@"Get-AppxPackage -AllUsers | Where-Object {{ $_.Name -like '*{name}*' }} | ForEach-Object {{ Remove-AppxPackage -AllUsers -Package $_.PackageFullName }}",
- $@"Get-AppxProvisionedPackage -Online | Where-Object {{ $_.PackageName -like '*{name}*' }} | ForEach-Object {{ Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName -AllUsers -Verbose }}"
- }).ToList();
+ await CommandExecutor.InvokeRunCommand(psCommands, true).ConfigureAwait(false);
- await CommandExecutor.InvokeRunCommand(string.Join(" ; ", psCommands), true).ConfigureAwait(false);
-
- CommandExecutor.RunCommandAsTrustedInstaller($@"/c for /d %i in ({string.Join(" ", packageNamesToRemove.Select(n => $@"""{Path.Combine(PathLocator.Folders.SystemDrive, "Program Files", "WindowsApps")}\*{n}*"""))}) do takeown /f ""%i"" /r /d Y & icacls ""%i"" /inheritance:r /remove S-1-5-32-544 S-1-5-11 S-1-5-32-545 S-1-5-18 & icacls ""%i"" /grant {Environment.UserName}:F & rd /s /q ""%i""");
- }
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c for /d %i in ({string.Join(" ", packageNamesToRemove.Select(n => $@"""{Path.Combine(PathLocator.Folders.SystemDrive, "Program Files", "WindowsApps")}\*{n}*"""))}) do takeown /f ""%i"" /r /d y && icacls ""%i"" /inheritance:r /remove S-1-5-32-544 S-1-5-11 S-1-5-32-545 S-1-5-18 && icacls ""%i"" /grant {Environment.UserName}:F && rd /s /q ""%i""");
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- switch (packageName)
- {
- case "Maps":
- RemoveTasks(mapsTasks);
- break;
- case "Widgets":
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Dsh", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
- break;
- case "Cortana":
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Speech_OneCore\Preferences", "ModelDownloadAllowed", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCloudSearch", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCortana", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowSearchToUseLocation", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "ConnectedSearchUseWeb", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "DisableWebSearch", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitInkCollection", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitTextCollection", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization\TrainedDataStore", "HarvestContacts", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Personalization\Settings", "AcceptedPrivacyPolicy", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Windows Search", "CortanaConsent", 0, RegistryValueKind.DWord);
- break;
- case "Phone":
- if (RegistryHelp.KeyExists(Registry.ClassesRoot, @"*\shellex\ContextMenuHandlers\ModernSharing", true))
- {
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"*\shellex\ContextMenuHandlers\SendTo");
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"*\shellex\ContextMenuHandlers\ModernShare");
- }
- else
- {
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"AllFilesystemObjects\shellex\ContextMenuHandlers\SendTo");
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"AllFilesystemObjects\shellex\ContextMenuHandlers\ModernSharing");
- }
- CommandExecutor.RunCommandAsTrustedInstaller($@"/c reg delete ""HKEY_CLASSES_ROOT\CLSID\{{7AD84985-87B4-4a16-BE58-8B72A5B390F7}}"" /f & reg delete ""HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{{7AD84985-87B4-4a16-BE58-8B72A5B390F7}}"" /f");
- break;
- case "Paint3D":
- try
+ switch (packageName)
+ {
+ case "Maps":
+ RemoveTasks(mapsTasks);
+ break;
+ case "Widgets":
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Dsh", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
+ break;
+ case "Cortana":
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Speech_OneCore\Preferences", "ModelDownloadAllowed", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCloudSearch", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCortana", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowSearchToUseLocation", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "ConnectedSearchUseWeb", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "DisableWebSearch", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitInkCollection", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitTextCollection", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization\TrainedDataStore", "HarvestContacts", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Personalization\Settings", "AcceptedPrivacyPolicy", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Windows Search", "CortanaConsent", 0, RegistryValueKind.DWord);
+ break;
+ case "Phone":
+ if (RegistryHelp.KeyExists(Registry.ClassesRoot, @"*\shellex\ContextMenuHandlers\ModernSharing", true))
+ {
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"*\shellex\ContextMenuHandlers\SendTo");
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"*\shellex\ContextMenuHandlers\ModernShare");
+ }
+ else
+ {
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"AllFilesystemObjects\shellex\ContextMenuHandlers\SendTo");
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"AllFilesystemObjects\shellex\ContextMenuHandlers\ModernSharing");
+ }
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c reg delete ""HKEY_CLASSES_ROOT\CLSID\{{7AD84985-87B4-4a16-BE58-8B72A5B390F7}}"" /f & reg delete ""HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{{7AD84985-87B4-4a16-BE58-8B72A5B390F7}}"" /f");
+ break;
+ case "Paint3D":
+ try
+ {
+ using RegistryKey baseKey = Registry.ClassesRoot.OpenSubKey("SystemFileAssociations", true);
+ if (baseKey != null)
{
- using RegistryKey baseKey = Registry.ClassesRoot.OpenSubKey("SystemFileAssociations", true);
- if (baseKey != null)
+ foreach (string subkey in baseKey.GetSubKeyNames())
{
- foreach (string subkey in baseKey.GetSubKeyNames())
+ try
{
- try
+ using RegistryKey assocKey = baseKey.OpenSubKey(subkey, true);
+ if (assocKey != null)
{
- using RegistryKey assocKey = baseKey.OpenSubKey(subkey, true);
- if (assocKey != null)
+ using RegistryKey shellKey = assocKey.OpenSubKey("Shell", true);
+ if (shellKey != null)
{
- using RegistryKey shellKey = assocKey.OpenSubKey("Shell", true);
- if (shellKey != null)
+ if (shellKey.GetSubKeyNames().Any(k => k.Equals("3D Print", StringComparison.OrdinalIgnoreCase)))
{
- if (shellKey.GetSubKeyNames().Any(k => k.Equals("3D Print", StringComparison.OrdinalIgnoreCase)))
- {
- RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, $@"SystemFileAssociations\{subkey}\shell\3D Print");
- }
+ RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, $@"SystemFileAssociations\{subkey}\shell\3D Print");
}
}
}
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
- baseKey.Close();
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
+ baseKey.Close();
}
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- break;
- case "Edge":
- string[] processes = { "msedge", "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.RunCommandAsTrustedInstaller(CommandExecutor.CleanCommand(string.Join(" & ", new[] {
- @"/c rmdir /s /q ""%LocalAppData%\Microsoft\Edge""",
- @"for /r ""%AppData%\Microsoft\Internet Explorer\Quick Launch"" %f in (*Edge*) do del ""%f""",
- @"del /q /f ""%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*Edge*.lnk""",
- $@"for /r ""{PathLocator.Folders.SystemDrive}ProgramData\Microsoft\Windows\Start Menu\Programs"" %f in (*Edge*) do del ""%f""",
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ break;
+ case "Edge":
+ 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.RunCommandAsTrustedInstaller("/c " + CommandExecutor.CleanCommand(string.Join(" & ", new[]
+ {
+ @"rmdir /s /q ""%LocalAppData%\Microsoft\Edge""",
+ @"rmdir /s /q ""%ProgramFiles%\Microsoft\Edge""",
+ @"for /r ""%AppData%\Microsoft\Internet Explorer\Quick Launch"" %f in (*Edge*) do del /f /q ""%f""",
+ @"del /q /f ""%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*Edge*""",
+ @"del /f /q ""%Public%\Desktop\*Edge*""",
+ @"del /f /q ""%UserProfile%\Desktop\*Edge*""",
+ $@"for /r ""{PathLocator.Folders.SystemDrive}ProgramData\Microsoft\Windows\Start Menu\Programs"" %f in (*Edge*) do del /f /q ""%f""",
$@"for /r ""{PathLocator.Folders.SystemDrive}Users"" %f in (*Edge*) do @if exist ""%f"" del /f /q ""%f""",
- $@"for /d %d in (""{PathLocator.Folders.SystemDrive}Program Files (x86)\Microsoft\*Edge*"") do rmdir /s /q ""%d""",
- $@"for /f ""delims="" %i in ('dir /b /s ""{PathLocator.Folders.SystemDrive}Windows\System32\Tasks\*Edge*""') do (if exist ""%i"" (if exist ""%i\"" (rmdir /s /q ""%i"") else (del /f /q ""%i"")))"})));
+ $@"for /f ""delims="" %i in ('dir /b /s ""{PathLocator.Folders.SystemDrive}Windows\System32\Tasks\*Edge*""') do (if exist ""%i"" (if exist ""%i\"" (rmdir /s /q ""%i"") else (del /f /q ""%i"")))"
+ })));
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Edge", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Edge", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Classes\MSEdgeHTM", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Clients\StartMenuInternet\Microsoft Edge", true);
- if (shouldRemoveWebView)
- {
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\edgeupdate", true);
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\edgeupdatem", true);
- 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);
- }
+ CommandExecutor.RunCommandAsTrustedInstaller(@"/c rmdir /s /q %LocalAppData%\Microsoft\Edge");
+ CommandExecutor.RunCommandAsTrustedInstaller(@"/c rmdir /s /q %ProgramFiles%\Microsoft\Edge");
+ CommandExecutor.RunCommandAsTrustedInstaller(@"/c for /r ""%AppData%\Microsoft\Internet Explorer\Quick Launch"" %f in (*Edge*) do del ""%f""");
+ CommandExecutor.RunCommandAsTrustedInstaller(@"/c del /q /f ""%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*Edge*.lnk""");
- 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}""");
+ CommandExecutor.RunCommandAsTrustedInstaller(@"/c del /q /f ""%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*Edge*.lnk""");
+ CommandExecutor.RunCommandAsTrustedInstaller(@"/c del /q /f ""%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*Edge*.lnk""");
- for (int i = 0; Directory.Exists(path) && i < 10; i++)
- {
- try { Directory.Delete(path, true); Thread.Sleep(300); }
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c for /r ""{PathLocator.Folders.SystemDrive}ProgramData\Microsoft\Windows\Start Menu\Programs"" %f in (*Edge*) do del ""%f""");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c for /r ""{PathLocator.Folders.SystemDrive}Users"" %f in (*Edge*) do @if exist ""%f"" del /f /q ""%f""");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c for /d %d in (""{PathLocator.Folders.SystemDrive}Program Files (x86)\Microsoft\*Edge*"") do rmdir /s /q ""%d""");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c for /f ""delims="" %i in ('dir /b /s ""{PathLocator.Folders.SystemDrive}Windows\System32\Tasks\*Edge*""') do (if exist ""%i"" (if exist ""%i\"" (rmdir /s /q ""%i"") else (del /f /q ""%i"")))");
- CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{path}' -Recurse -Force", true);
- }
- }
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Edge", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Edge", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Classes\MSEdgeHTM", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Clients\StartMenuInternet\Microsoft Edge", true);
+
+ if (shouldRemoveWebView)
+ {
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\edgeupdate", true);
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\edgeupdatem", true);
+ 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);
+ }
+
+ 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}""");
- foreach (string folder in new[] { "Edge", "EdgeCore", "EdgeUpdate", "Temp", "EdgeWebView" })
+ for (int i = 0; Directory.Exists(path) && i < 10; i++)
{
- if (!shouldRemoveWebView && (folder == "EdgeWebView" || folder == "EdgeCore" || folder == "EdgeUpdate"))
- {
- continue;
- }
+ try { Directory.Delete(path, true); Thread.Sleep(300); }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft", folder);
- UnlockHandleHelper.UnlockDirectory(dir);
- RemoveDirectory(dir);
+ CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{path}' -Recurse -Force", true);
}
+ }
- try
+ foreach (string folder in new[] { "Edge", "EdgeCore", "EdgeUpdate", "Temp", "EdgeWebView" })
+ {
+ if (!shouldRemoveWebView && (folder == "EdgeWebView" || folder == "EdgeCore" || folder == "EdgeUpdate"))
{
- using RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\InboxApplications");
- foreach (string subKey in key?.GetSubKeyNames() ?? Array.Empty<string>())
+ continue;
+ }
+
+ string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft", folder);
+ UnlockHandleHelper.UnlockDirectory(dir);
+ RemoveDirectory(dir);
+ }
+
+ try
+ {
+ using RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\InboxApplications");
+ foreach (string subKey in key?.GetSubKeyNames() ?? Array.Empty<string>())
+ {
+ using RegistryKey subKeyEntry = key.OpenSubKey(subKey);
+ string path = subKeyEntry?.GetValue("Path") as string;
+ if (!string.IsNullOrEmpty(path) && path.Equals("Edge"))
{
- using RegistryKey subKeyEntry = key.OpenSubKey(subKey);
- string path = subKeyEntry?.GetValue("Path") as string;
- if (!string.IsNullOrEmpty(path) && path.Equals("Edge"))
+ if (!shouldRemoveWebView && path.Contains("WebView"))
{
- if (!shouldRemoveWebView && path.Contains("WebView"))
- {
- continue;
- }
+ continue;
+ }
- if (path.EndsWith(@"\AppxManifest.xml", StringComparison.OrdinalIgnoreCase))
- {
- path = path.Replace(@"\AppxManifest.xml", "").Trim();
- }
+ if (path.EndsWith(@"\AppxManifest.xml", StringComparison.OrdinalIgnoreCase))
+ {
+ path = path.Replace(@"\AppxManifest.xml", "").Trim();
+ }
- RemoveDirectory(path);
+ RemoveDirectory(path);
- key.DeleteSubKey(subKey);
+ key.DeleteSubKey(subKey);
- return;
- }
+ return;
}
}
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- break;
- default:
- break;
- }
- });
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ break;
+ default:
+ break;
+ }
}
}
}
diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.cs
index 9cb97dcf..fd5021fa 100644
--- a/.Source/GTweak/View/PakagesView.xaml.cs
+++ b/.Source/GTweak/View/PakagesView.xaml.cs
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
-using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
@@ -17,6 +16,7 @@ namespace GTweak.View
{
private TimerControlManager _timer = default;
private readonly BackgroundQueue _backgroundQueue = new BackgroundQueue();
+ private readonly BackgroundWorker backgroundWorker = new BackgroundWorker();
private readonly UninstallingPakages _uninstalling = new UninstallingPakages();
private bool _isWebViewRemoval = false;
@@ -27,13 +27,24 @@ namespace GTweak.View
Unloaded += delegate { _timer.Stop(); };
Loaded += delegate
{
- _timer = new TimerControlManager(TimeSpan.Zero, TimerControlManager.TimerMode.CountUp, async time =>
+ backgroundWorker.DoWork += delegate
{
- if ((int)time.TotalSeconds % 3 == 0)
+ _uninstalling.GetInstalledPackages();
+ };
+ backgroundWorker.RunWorkerCompleted += delegate
+ {
+ Dispatcher.Invoke(() => { UninstallingPakages.OnPackagesChanged(); });
+ };
+
+ _timer = new TimerControlManager(TimeSpan.Zero, TimerControlManager.TimerMode.CountUp, time =>
+ {
+ if ((int)time.TotalSeconds % 3 != 0)
+ {
+ return;
+ }
+
+ if (!backgroundWorker.IsBusy)
{
- BackgroundWorker backgroundWorker = new BackgroundWorker();
- backgroundWorker.DoWork += delegate { _uninstalling.GetInstalledPackages(); };
- backgroundWorker.RunWorkerCompleted += delegate { Dispatcher.Invoke(() => { UninstallingPakages.OnPackagesChanged(); }); };
backgroundWorker.RunWorkerAsync();
}
});
@@ -71,13 +82,10 @@ namespace GTweak.View
await _backgroundQueue.QueueTask(async () =>
{
- Dispatcher.Invoke(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, true); });
-
- await UninstallingPakages.RestoreOneDriveFolder();
-
- await Task.Delay(3000);
+ await Dispatcher.InvokeAsync(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, true); });
- Dispatcher.Invoke(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, false); });
+ try { await UninstallingPakages.RestoreOneDriveFolder(); }
+ finally { await Dispatcher.InvokeAsync(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, false); }); }
});
}
}
@@ -96,13 +104,10 @@ namespace GTweak.View
await _backgroundQueue.QueueTask(async () =>
{
- Dispatcher.Invoke(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, true); }); ;
-
- await UninstallingPakages.RemoveAppxPackage(packageName, _isWebViewRemoval);
-
- await Task.Delay(3000);
+ await Dispatcher.InvokeAsync(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, true); });
- Dispatcher.Invoke(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, false); });
+ try { await UninstallingPakages.RemoveAppxPackage(packageName, _isWebViewRemoval); }
+ finally { await Dispatcher.InvokeAsync(() => { UninstallingPakages.HandleAvailabilityStatus(packageName, false); }); }
await Dispatcher.BeginInvoke(new Action(() =>
{