Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix win defender file deletion logic and nsudo execution paths fix silent crash on overlay window close
Greedeksdfe67911dd0d
diff --git a/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.cs b/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.csindex 1dcb16a5..23775aad 100644--- a/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.cs+++ b/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.cs@@ -1,4 +1,4 @@-using System;+using System;using System.Runtime.InteropServices;using System.Windows.Forms;using System.Windows.Input;@@ -20,7 +20,7 @@ namespace GTweak.Utilities.Helpers[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]internal static extern IntPtr SetWindowsHookEx(int id, LowLevelKeyboardProc callback, IntPtr hMod, uint dwThreadId);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]- private static extern bool UnhookWindowsHookEx(IntPtr hook);+ internal static extern bool UnhookWindowsHookEx(IntPtr hook);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]private static extern IntPtr CallNextHookEx(IntPtr hook, int nCode, IntPtr wp, IntPtr lp);[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.csindex 2e2a8d75..0c2f5814 100644--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs@@ -54,7 +54,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManagerSet-MpPreference -MAPSReporting 2Set-MpPreference -PUAProtection Enabled");- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c " ++ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c " +@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v LocalSettingOverrideDisableOnAccessProtection /f & " +@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v LocalSettingOverrideRealtimeScanDirection /f & " +@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v LocalSettingOverrideDisableIOAVProtection /f & " +@@ -77,7 +77,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v DisablePrivacyMode /f & " +@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v DisableBlockAtFirstSeen /f");- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c " ++ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c " +@"reg delete ""HKCU\Software\Microsoft\Windows\CurrentVersion\AppHost"" /v EnableWebContentEvaluation /t REG_DWORD /d 0 /f & " +@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\MicrosoftEdge\PhishingFilter"" /v EnabledV9 /f & " +@"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender"" /v PUAProtection /t REG_DWORD /d 2 /f & " +@@ -91,7 +91,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager@"reg add ""HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WINEVT\Channels\Microsoft-Windows-DeviceGuard/Verbose"" /v Enabled /t REG_DWORD /d 1 /f");RegistryHelp.CreateFolder(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer");- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer", "SmartScreenEnabled", "On", RegistryValueKind.String);+ RegistryHelp.DeleteValue(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer", "SmartScreenEnabled");RegistryHelp.DeleteValue(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\System", "EnableSmartScreen");RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows Defender");RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Microsoft Antimalware");@@ -104,7 +104,8 @@ namespace GTweak.Utilities.Tweaks.DefenderManagerRegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\PrivateProfile", "DisableNotifications", 0, RegistryValueKind.DWord);RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile", "DisableNotifications", 0, RegistryValueKind.DWord);RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows Defender Security Center");- RegistryHelp.DeleteFolderTree(Registry.CurrentUser, @"SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge");+ RegistryHelp.DeleteValue(Registry.CurrentUser, @"SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge", "EnabledV9");+ RegistryHelp.DeleteValue(Registry.CurrentUser, @"SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge", "PreventOverride");RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\WMI\Autologger\DefenderApiLogger", "Start", 1, RegistryValueKind.DWord);RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\WMI\Autologger\DefenderAuditLogger", "Start", 1, RegistryValueKind.DWord);@@ -145,7 +146,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManagerRegistryHelp.DeleteValue(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows defender\Windows defender Exploit Guard\Controlled Folder Access", "EnableControlledFolderAccess");RegistryHelp.DeleteValue(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows Defender\Windows Defender Exploit Guard\Network Protection", "EnableNetworkProtection");- CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo}-U:T -P:E -CreatePath:S -ShowWindowMode:Hide cmd /c " ++ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide cmd /c " +@"reg delete HKLM\SYSTEM\CurrentControlSet\Services\WinDefend /v AutorunsDisabled /f & " +@"reg add HKLM\SYSTEM\CurrentControlSet\Services\wscsvc /v DelayedAutoStart /t REG_DWORD /d 1 /f & " +@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\WdFilter\Instances\WdFilter Instance"" /v Altitude /t REG_SZ /d 328010 /f & " +@@ -404,17 +405,17 @@ namespace GTweak.Utilities.Tweaks.DefenderManagercontinue;}- foreach (string filePath in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly))+ foreach (string file in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly)){- CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""takeown /f \""{filePath}\"" /r /d y && icacls \""{filePath}\"" /inheritance:r /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 && icacls \""{filePath}\"" /grant {Environment.UserName}:F /t && del /q \""{filePath}\""""");+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""{$@"takeown /f ""{file}"" /a & icacls ""{file}"" /inheritance:r /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 & icacls ""{file}"" /grant ""{Environment.UserName}"":F & del /f /q ""{file}"""}""");- for (int i = 0; Directory.Exists(filePath) && i < 10; i++)+ for (int i = 0; File.Exists(file) && i < 10; i++){- try { Directory.Delete(filePath, true); }+ try { File.Delete(file); }catch (Exception ex) { ErrorLogging.LogDebug(ex); }- TakingOwnership.GrantAdministratorsAccess(filePath, TakingOwnership.SE_OBJECT_TYPE.SE_FILE_OBJECT);- CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""del /q ""{filePath}""""");+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""del /f /q ""{file}""""");+ TakingOwnership.GrantAdministratorsAccess(file, TakingOwnership.SE_OBJECT_TYPE.SE_FILE_OBJECT);Thread.Sleep(500);}diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.csindex c1388beb..ed0632f2 100644--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs@@ -149,7 +149,10 @@ namespace GTweak.Utilities.Tweaks{BlockWDefender(state);ArchiveManager.Unarchive(PathLocator.Executable.NSudo, Properties.Resources.NSudoLC);- ArchiveManager.Unarchive(PathLocator.Executable.DisablingWD, Properties.Resources.DisablingWD);+ if (state == false)+ {+ ArchiveManager.Unarchive(PathLocator.Executable.DisablingWD, Properties.Resources.DisablingWD);+ }if (canShowWindow){diff --git a/.Source/GTweak/Windows/OverlayWindow.xaml.cs b/.Source/GTweak/Windows/OverlayWindow.xaml.csindex 6aa67ef4..a310e877 100644--- a/.Source/GTweak/Windows/OverlayWindow.xaml.cs+++ b/.Source/GTweak/Windows/OverlayWindow.xaml.cs@@ -1,3 +1,4 @@+using System;using System.ComponentModel;using System.Diagnostics;using System.Windows;@@ -24,13 +25,14 @@ namespace GTweak.Windows{Closing -= Window_Closing;e!.Cancel = true;- BeginAnimation(OpacityProperty, FactoryAnimation.CreateTo(0.15, () =>++ if (disablingWinKeys.ptrHook != IntPtr.Zero){- ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;- disablingWinKeys.objKeyboardProcess = new DisablingWinKeys.LowLevelKeyboardProc(disablingWinKeys.CaptureKey);- disablingWinKeys.ptrHook = DisablingWinKeys.SetWindowsHookEx(13, disablingWinKeys.objKeyboardProcess, DisablingWinKeys.GetModuleHandle(objCurrentModule.ModuleName), 1);- Close();- }));+ DisablingWinKeys.UnhookWindowsHookEx(disablingWinKeys.ptrHook);+ disablingWinKeys.ptrHook = IntPtr.Zero;+ }++ BeginAnimation(OpacityProperty, FactoryAnimation.CreateTo(0.15, () => { Close(); }));}}