Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
add UnlockHandleHelper & upd deleting temporary files/update cache/edge & ref
Greedeksae3552cca1df
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csprojindex 2cffc323..7e1f41c4 100644--- a/.Source/GTweak/GTweak.csproj+++ b/.Source/GTweak/GTweak.csproj@@ -151,6 +151,7 @@<Compile Include="Converters\ScrollFadeMaskConverter.cs" /><Compile Include="Utilities\Configuration\DiskTypeIdentifier.cs" /><Compile Include="Utilities\Configuration\HardwareData.cs" />+ <Compile Include="Utilities\Helpers\UnlockHandleHelper.cs" /><Compile Include="Utilities\Maintenance\ClearingMemory.cs" /><Compile Include="Utilities\Maintenance\RegistryExporter.cs" /><Compile Include="Utilities\Tweaks\ConfidentialityTweaks.cs" />diff --git a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs b/.Source/GTweak/Utilities/Helpers/CommandExecutor.csindex 4c0a7e3d..141391a4 100644--- a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs+++ b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs@@ -1,6 +1,8 @@using System;using System.Diagnostics;+using System.Linq;using System.Text;+using System.Text.RegularExpressions;using System.Threading.Tasks;using GTweak.Utilities.Controls;@@ -111,5 +113,34 @@ namespace GTweak.Utilities.Helpersprocess.Exited += (sender, args) => tcs.TrySetResult(null);return tcs.Task;}++ internal static string CleanCommand(string rawCommand)+ {+ if (string.IsNullOrWhiteSpace(rawCommand))+ {+ return string.Empty;+ }++ var lines = rawCommand+ .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)+ .Select(line => line.Trim())+ .Where(line => !string.IsNullOrEmpty(line))+ .Select(line => Regex.Replace(line, @"\s+", " "))+ .ToList();++ if (lines.Count == 0)+ {+ return "";+ }++ if (lines.Count == 1)+ {+ return lines[0];+ }++ string separator = rawCommand.Contains("&&") ? " && " : rawCommand.Contains("&") ? " & " : " && ";++ return string.Join(separator, lines);+ }}}\ No newline at end of filediff --git a/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs b/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.csnew file mode 100644index 00000000..48bd3c2d--- /dev/null+++ b/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs@@ -0,0 +1,157 @@+using System;+using System.Collections.Generic;+using System.Diagnostics;+using System.IO;+using System.Runtime.InteropServices;+using GTweak.Utilities.Controls;++namespace GTweak.Utilities.Helpers+{+ internal static class UnlockHandleHelper+ {+ private const int ERROR_SUCCESS = 0;+ private const int ERROR_MORE_DATA = 234;++ [StructLayout(LayoutKind.Sequential)]+ private struct RM_UNIQUE_PROCESS+ {+ public int dwProcessId;+ public System.Runtime.InteropServices.ComTypes.FILETIME ProcessStartTime;+ }++ private enum RM_APP_TYPE+ {+ RmUnknownApp = 0,+ RmMainWindow = 1,+ RmOtherWindow = 2,+ RmService = 3,+ RmExplorer = 4,+ RmConsole = 5,+ RmCritical = 1000+ }++ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]+ private struct RM_PROCESS_INFO+ {+ public RM_UNIQUE_PROCESS Process;+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]+ public string strAppName;+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]+ public string strServiceShortName;+ public RM_APP_TYPE ApplicationType;+ public uint AppStatus;+ public uint TSSessionId;+ [MarshalAs(UnmanagedType.Bool)]+ public bool bRestartable;+ }++ [DllImport("rstrtmgr.dll", CharSet = CharSet.Unicode)]+ private static extern int RmStartSession(out uint pSessionHandle, int dwSessionFlags, string strSessionKey);++ [DllImport("rstrtmgr.dll", CharSet = CharSet.Unicode)]+ private static extern int RmRegisterResources(uint pSessionHandle, uint nFiles, string[] rgsFilenames, uint nApplications, IntPtr rgApplications, uint nServices, string[] rgsServiceNames);++ [DllImport("rstrtmgr.dll")]+ private static extern int RmGetList(uint dwSessionHandle, out uint pnProcInfoNeeded, ref uint pnProcInfo, [In, Out] RM_PROCESS_INFO[] rgAffectedApps, out uint lpdwRebootReasons);++ [DllImport("rstrtmgr.dll")]+ private static extern int RmEndSession(uint pSessionHandle);++ internal static void UnlockDirectory(string directoryPath)+ {+ if (string.IsNullOrWhiteSpace(directoryPath))+ {+ return;+ }++ if (!Directory.Exists(directoryPath))+ {+ return;+ }++ HashSet<int> pids = GetUnlockProcessIds(directoryPath);++ foreach (int pid in pids)+ {+ try+ {+ Process process = Process.GetProcessById(pid);+ if (process.HasExited)+ {+ continue;+ }++ try+ {+ process.CloseMainWindow();+ process.WaitForExit(1000);+ }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }++ if (!process.HasExited)+ {+ process.Kill();+ process.WaitForExit(2000);+ }+ }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ }+ }++ private static HashSet<int> GetUnlockProcessIds(string directoryPath)+ {+ HashSet<int> result = new HashSet<int>();++ string[] files;+ try+ {+ files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);+ if (files.Length == 0)+ {+ files = new[] { Path.GetFullPath(directoryPath) };+ }+ }+ catch { files = new[] { Path.GetFullPath(directoryPath) }; }++ string sessionKey = Guid.NewGuid().ToString();++ if (RmStartSession(out uint sessionHandle, 0, sessionKey) != ERROR_SUCCESS)+ {+ return result;+ }++ try+ {+ if (RmRegisterResources(sessionHandle, (uint)files.Length, files, 0, IntPtr.Zero, 0, null) != ERROR_SUCCESS)+ {+ return result;+ }++ uint count = 0;++ int res = RmGetList(sessionHandle, out uint needed, ref count, null, out uint rebootReasons);+ if (res != ERROR_MORE_DATA)+ {+ return result;+ }++ RM_PROCESS_INFO[] infos = new RM_PROCESS_INFO[needed];+ count = needed;++ if (RmGetList(sessionHandle, out needed, ref count, infos, out rebootReasons) != ERROR_SUCCESS)+ {+ return result;+ }++ foreach (var info in infos)+ {+ result.Add(info.Process.dwProcessId);+ }+ }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ finally { RmEndSession(sessionHandle); }++ return result;+ }+ }+}diff --git a/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs b/.Source/GTweak/Utilities/Maintenance/ClearingMemory.csindex ae269d91..8271bffc 100644--- a/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs+++ b/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs@@ -192,17 +192,16 @@ namespace GTweak.Utilities.Maintenance{string dir = PathLocator.Folders.WindowsOld;- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{dir}\" /r /d y & icacls \"{dir}\" /inheritance:r /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 & icacls \"{dir}\" /grant {Environment.UserName}:F /t & rd /s /q \"{dir}\"");+ UnlockHandleHelper.UnlockDirectory(dir);++ CommandExecutor.RunCommandAsTrustedInstaller($@"/c takeown /f ""{dir}"" /r /d y && icacls ""{dir}"" /inheritance:r && icacls ""{dir}"" /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 && icacls ""{dir}"" /grant {Environment.UserName}:F /t && rd /s /q ""{dir}""");for (int i = 0; Directory.Exists(dir) && i < 10; i++){- try { Directory.Delete(dir, true); }+ try { Directory.Delete(dir, true); Thread.Sleep(300); }catch (Exception ex) { ErrorLogging.LogDebug(ex); }- TakingOwnership.GrantAdministratorsAccess(dir, TakingOwnership.SE_OBJECT_TYPE.SE_FILE_OBJECT);- CommandExecutor.RunCommandAsTrustedInstaller($"/c rd /s /q \"{dir}\"");-- Thread.Sleep(500);+ CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{dir}' -Recurse -Force", true);}}diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.csindex 948f10f0..eb1bd9e8 100644--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs@@ -4,7 +4,6 @@ using System.Diagnostics;using System.IO;using System.Linq;using System.Text;-using System.Text.RegularExpressions;using System.Threading;using GTweak.Utilities.Controls;using GTweak.Utilities.Helpers;@@ -193,14 +192,14 @@ namespace GTweak.Utilities.Tweaks.DefenderManagerManageExclusions(false);SetTaskState(true, winDefenderTasks);- CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c {CleanCommand(string.Join(" & ", services.Select(kv => $@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\{kv.Key}"" /v Start /t REG_DWORD /d {kv.Value} /f")))}""");+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c {CommandExecutor.CleanCommand(string.Join(" & ", services.Select(kv => $@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\{kv.Key}"" /v Start /t REG_DWORD /d {kv.Value} /f")))}""");foreach (var (path, normal, block) in fileMappings){string sourcePath = Path.Combine(path, block);string targetPath = Path.Combine(path, normal);- CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""{CleanCommand(string.Join(" && ", new[] {+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""{CommandExecutor.CleanCommand(string.Join(" && ", new[] {$@"takeown /f ""{sourcePath}"" /a",$@"rename ""{sourcePath}"" ""{normal}""",$@"icacls ""{targetPath}"" /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",@@ -231,7 +230,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManagerCommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""rename ""{Path.Combine(path, normal)}"" ""{block}""""");}- CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c {CleanCommand(string.Join(" & ", services.Select(kv => $@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\{kv.Key}"" /v Start /t REG_DWORD /d 4 /f")))}""");+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c {CommandExecutor.CleanCommand(string.Join(" & ", services.Select(kv => $@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\{kv.Key}"" /v Start /t REG_DWORD /d 4 /f")))}""");CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c " +$"for /d %D in (\"{Path.Combine(PathLocator.Folders.SystemDrive, @"ProgramData\\Microsoft\\Windows Defender\\Platform\\*")}\") do if exist \"%D\\MsMpEng.exe\" ren \"%D\\MsMpEng.exe\" BlockAntimalware.exe & " +@@ -510,34 +509,6 @@ namespace GTweak.Utilities.Tweaks.DefenderManagercatch (Exception ex) { ErrorLogging.LogDebug(ex); }}- private static string CleanCommand(string rawCommand)- {- if (string.IsNullOrWhiteSpace(rawCommand))- {- return string.Empty;- }-- var lines = rawCommand- .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)- .Select(line => line.Trim())- .Where(line => !string.IsNullOrEmpty(line))- .Select(line => Regex.Replace(line, @"\s+", " "))- .ToList();-- if (lines.Count == 0)- {- return "";- }-- if (lines.Count == 1)- {- return lines[0];- }-- string separator = rawCommand.Contains("&&") ? " && " : rawCommand.Contains("&") ? " & " : " && ";-- return string.Join(separator, lines);- }}}diff --git a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.csindex cc1435be..f806f7e9 100644--- a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs+++ b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs@@ -2,7 +2,6 @@ using System;using System.Collections.Generic;using System.IO;using System.Linq;-using System.Threading;using System.Threading.Tasks;using GTweak.Utilities.Controls;using GTweak.Utilities.Helpers;@@ -208,11 +207,26 @@ namespace GTweak.Utilities.Tweaksif (isDisabled){- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{currentFilePath}\" & icacls \"{currentFilePath}\" /inheritance:r /remove S-1-5-32-544 S-1-5-11 S-1-5-32-545 S-1-5-18 & icacls \"{currentFilePath}\" /grant {Environment.UserName}:F & rename \"{currentFilePath}\" \"{Path.GetFileName(targetFilePath)}\"");+ CommandExecutor.RunCommandAsTrustedInstaller($@"cmd /c ""{CommandExecutor.CleanCommand(string.Join(" && ", new[] {+ $@"takeown /f ""{currentFilePath}"" /a",+ $@"icacls ""{currentFilePath}"" /inheritance:r /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18",+ $@"icacls ""{currentFilePath}"" /grant ""{Environment.UserName}"":F",+ $@"rename ""{currentFilePath}"" ""{Path.GetFileName(targetFilePath)}"""}))}""");}else{- CommandExecutor.RunCommandAsTrustedInstaller($"/c rename \"{currentFilePath}\" \"{Path.GetFileName(targetFilePath)}\" & icacls \"{targetFilePath}\" /reset & takeown /f \"{targetFilePath}\" /a & icacls \"{targetFilePath}\" /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464");+ CommandExecutor.RunCommandAsTrustedInstaller($@"cmd /c ""{CommandExecutor.CleanCommand(string.Join(" && ", new[] {+ $@"takeown /f ""{currentFilePath}"" /a",+ $@"rename ""{currentFilePath}"" ""{Path.GetFileName(targetFilePath)}""",+ $@"icacls ""{targetFilePath}"" /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",+ $@"icacls ""{targetFilePath}"" /inheritance:r",+ $@"icacls ""{targetFilePath}"" /grant *S-1-5-32-544:F",+ $@"icacls ""{targetFilePath}"" /grant *S-1-5-32-545:R",+ $@"icacls ""{targetFilePath}"" /grant *S-1-5-18:F",+ $@"icacls ""{targetFilePath}"" /grant *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464:F",+ $@"icacls ""{targetFilePath}"" /grant *S-1-15-2-1:R",+ $@"icacls ""{targetFilePath}"" /grant *S-1-15-2-2:R",+ $@"icacls ""{targetFilePath}"" /remove ""{Environment.UserName}"""}))}""");}}catch (Exception ex) { ErrorLogging.LogDebug(ex); }@@ -439,17 +453,16 @@ namespace GTweak.Utilities.Tweaksforeach (string path in new[] { $@"{PathLocator.Folders.SystemDrive}Windows\SoftwareDistribution\Download", $@"{PathLocator.Folders.SystemDrive}Windows\SoftwareDistribution\DataStore", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Windows", "DeliveryOptimization") }){- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{path}\" /r /d y & icacls \"{path}\" /inheritance:r /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}\"");+ UnlockHandleHelper.UnlockDirectory(path);- for (int i = 0; Directory.Exists(path) && i < 10; i++)+ 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}""");++ for (int i = 0; Directory.Exists(path) && i < 5; i++){try { Directory.Delete(path, true); }catch (Exception ex) { ErrorLogging.LogDebug(ex); }- TakingOwnership.GrantAdministratorsAccess(path, TakingOwnership.SE_OBJECT_TYPE.SE_FILE_OBJECT);- CommandExecutor.RunCommandAsTrustedInstaller($"/c rd /s /q \"{path}\"");-- Thread.Sleep(500);+ CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{path}' -Recurse -Force", true);}}diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.csindex c424cd3a..5e3ab16d 100644--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs@@ -107,7 +107,7 @@ namespace GTweak.Utilities.Tweaks}catch (Exception ex) { ErrorLogging.LogDebug(ex); }- _сontrolWriter.Button[8] =+ _сontrolWriter.Button[8] =RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\7516b95f-f776-4464-8c53-06167f40cc99\8EC4B3A5-6868-48c2-BE75-4F3044BE88A7", "Attributes", "2");_сontrolWriter.Button[9] =@@ -140,8 +140,8 @@ namespace GTweak.Utilities.Tweaks_сontrolWriter.Button[17] =RegistryHelp.CheckValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers", "DisableAutoplay", "1");- _сontrolWriter.Button[18] =- !RegistryHelp.GetValue($@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\{_currentPowerGuid}", "Description", string.Empty).Contains("-18") &&+ _сontrolWriter.Button[18] =+ !RegistryHelp.GetValue($@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\{_currentPowerGuid}", "Description", string.Empty).Contains("-18") &&!RegistryHelp.GetValue($@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\{_currentPowerGuid}", "FriendlyName", string.Empty).Contains("-19");_сontrolWriter.Button[19] = _isBluetoothStatus;diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.csindex 8ab4bb87..c01ffd97 100644--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs@@ -250,18 +250,19 @@ namespace GTweak.Utilities.Tweakscatch (Exception ex) { ErrorLogging.LogDebug(ex); }break;case "Edge":- string[] processes = { "smartscreen", "msedge", "pwahelper", "edgeupdate", "edgeupdatem", "msedgewebview2", "microsoftedgeupdate", "msedgewebviewhost", "msedgeuserbroker", "usocoreworker", "runtimebroker", "widgets" };+ 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(@"/c rmdir /s /q %LocalAppData%\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""");- 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.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""",+ $@"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"")))"})));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);@@ -288,17 +289,14 @@ namespace GTweak.Utilities.Tweaksstatic void RemoveDirectory(string path){- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{path}\" /r /d y & icacls \"{path}\" /inheritance:r /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 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}""");for (int i = 0; Directory.Exists(path) && i < 10; i++){- try { Directory.Delete(path, true); }+ try { Directory.Delete(path, true); Thread.Sleep(300); }catch (Exception ex) { ErrorLogging.LogDebug(ex); }- TakingOwnership.GrantAdministratorsAccess(path, TakingOwnership.SE_OBJECT_TYPE.SE_FILE_OBJECT);- CommandExecutor.RunCommandAsTrustedInstaller($"/c rd /s /q \"{path}\"");-- Thread.Sleep(500);+ CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{path}' -Recurse -Force", true);}}@@ -309,8 +307,9 @@ namespace GTweak.Utilities.Tweakscontinue;}- CommandExecutor.RunCommandAsTrustedInstaller("/c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));- RemoveDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft", folder));+ string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft", folder);+ UnlockHandleHelper.UnlockDirectory(dir);+ RemoveDirectory(dir);}try