Skip to content

Portable Tool for an Ideal Windows Setup

upd. Windows Defender disable processes - 25H2 & remove files

Greedeks5653793c0af0
diff --git a/.Source/GTweak/Properties/Resources.Designer.cs b/.Source/GTweak/Properties/Resources.Designer.cs
index e6e3e097..fe37fa92 100644
--- a/.Source/GTweak/Properties/Resources.Designer.cs
+++ b/.Source/GTweak/Properties/Resources.Designer.cs
@@ -1,6 +1,7 @@
namespace GTweak.Properties {
using System;
+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
diff --git a/.Source/GTweak/Resources/DisablingWD.gz b/.Source/GTweak/Resources/DisablingWD.gz
index 13399364..932bf8e3 100644
Binary files a/.Source/GTweak/Resources/DisablingWD.gz and b/.Source/GTweak/Resources/DisablingWD.gz differ
diff --git a/.Source/GTweak/Utilities/Controls/PathLocator.cs b/.Source/GTweak/Utilities/Controls/PathLocator.cs
index b66db693..9b784f44 100644
--- a/.Source/GTweak/Utilities/Controls/PathLocator.cs
+++ b/.Source/GTweak/Utilities/Controls/PathLocator.cs
@@ -289,8 +289,6 @@ namespace GTweak.Utilities.Controls
internal static readonly string OneDrive = FindExecutablePath("onedrivesetup.exe");
- internal static readonly string NSudo = Path.Combine(Folders.DefenderBackup, "NSudoLC.exe");
-
internal static (string Normal, string Block) UsoClient =>
(
Path.Combine(Environment.SystemDirectory, "usoclient.exe"),
@@ -306,6 +304,8 @@ namespace GTweak.Utilities.Controls
internal static readonly string MpCmdRun = Path.Combine(Folders.SystemDrive, "Program Files", "Windows Defender", "MpCmdRun.exe");
internal static readonly string DisablingWD = Path.Combine(Folders.DefenderBackup, "DisablingWD.exe");
+
+ internal static readonly string NSudo = Path.Combine(Folders.DefenderBackup, "NSudoLC.exe");
}
internal static class Files
diff --git a/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs b/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs
index cacc3c47..9b723fbc 100644
--- a/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs
+++ b/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs
@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
+using System.Windows.Shapes;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
using GTweak.Utilities.Managers;
@@ -191,19 +192,18 @@ namespace GTweak.Utilities.Maintenance
if (shouldRemoveWinOld)
{
string dir = PathLocator.Folders.WindowsOld;
- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{dir}\"");
- CommandExecutor.RunCommandAsTrustedInstaller($"/c icacls \"{dir}\" /inheritance:r /remove S-1-5-32-544 S-1-5-11 S-1-5-32-545 S-1-5-18");
- CommandExecutor.RunCommandAsTrustedInstaller($"/c icacls \"{dir}\" /grant {Environment.UserName}:F");
- CommandExecutor.RunCommandAsTrustedInstaller($"/c rd /s /q \"{dir}\"");
- Thread.Sleep(2000);
+ 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}\"");
- if (Directory.Exists(dir))
+ for (int i = 0; Directory.Exists(dir) && i < 10; i++)
{
- try { Directory.Delete(dir, true); } catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ try { Directory.Delete(dir, true); }
+ 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(2000);
+
+ Thread.Sleep(500);
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
index 9de2f881..2f82111e 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
@@ -87,51 +87,51 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
try
{
Directory.CreateDirectory(PathLocator.Folders.DefenderBackup);
+ Dictionary<string, Dictionary<string, object>> allValues = new Dictionary<string, Dictionary<string, object>>();
+ Dictionary<string, string> aclDataDict = new Dictionary<string, string>();
- if (!File.Exists(PathLocator.Files.BackupDataJson) && !File.Exists(PathLocator.Files.BackupRightsAcl))
+ if (_storageRegPaths == null || _storageRegPaths.Count == 0)
{
- Dictionary<string, Dictionary<string, object>> allValues = new Dictionary<string, Dictionary<string, object>>();
- Dictionary<string, string> aclDataDict = new Dictionary<string, string>();
+ return;
+ }
+
+ foreach (var entry in _storageRegPaths)
+ {
+ string path = entry.Key;
+ RegistryKey baseKey = entry.Value;
- if (_storageRegPaths == null || _storageRegPaths.Count == 0)
+
+ using RegistryKey key = baseKey.OpenSubKey(path, false);
+ if (key == null)
{
- return;
+ continue;
}
- foreach (var entry in _storageRegPaths)
+ Dictionary<string, object> values = new Dictionary<string, object>();
+ foreach (string valueName in key.GetValueNames())
{
- string path = entry.Key;
- RegistryKey baseKey = entry.Value;
-
- using RegistryKey key = baseKey.OpenSubKey(path, false);
- if (key == null)
- {
- continue;
- }
-
- Dictionary<string, object> values = new Dictionary<string, object>();
- foreach (string valueName in key.GetValueNames())
- {
- values[valueName] = key.GetValue(valueName);
- }
- allValues[path] = values;
+ values[valueName] = key.GetValue(valueName);
+ }
+ allValues[path] = values;
- try
- {
- RegistrySecurity security = key.GetAccessControl();
- string aclData = security.GetSecurityDescriptorSddlForm(AccessControlSections.All);
- aclDataDict[path] = aclData;
- }
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ try
+ {
+ RegistrySecurity security = key.GetAccessControl();
+ string aclData = security.GetSecurityDescriptorSddlForm(AccessControlSections.All);
+ aclDataDict[path] = aclData;
}
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+
- File.WriteAllText(PathLocator.Files.BackupDataJson, JsonConvert.SerializeObject(allValues, Formatting.Indented));
- File.WriteAllText(PathLocator.Files.BackupRightsAcl, JsonConvert.SerializeObject(aclDataDict, Formatting.Indented));
}
+
+ File.WriteAllText(PathLocator.Files.BackupDataJson, JsonConvert.SerializeObject(allValues, Formatting.Indented));
+ File.WriteAllText(PathLocator.Files.BackupRightsAcl, JsonConvert.SerializeObject(aclDataDict, Formatting.Indented));
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
+
internal static void ImportRights()
{
if (File.Exists(PathLocator.Files.BackupDataJson) && File.Exists(PathLocator.Files.BackupRightsAcl))
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
index a4b7708f..45207e62 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
@@ -4,6 +4,7 @@ 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;
@@ -42,6 +43,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
(PathLocator.Folders.WindowsDefender, "MpCopyAccelerator.exe", "BlockMpCopyAccelerator.exe"),
(PathLocator.Folders.WindowsDefender, "DlpUserAgent.exe", "BlockDlpUserAgent.exe"),
(PathLocator.Folders.WindowsDefender, "MpDlpCmd.exe", "BlockMpDlpCmd.exe"),
+ (PathLocator.Folders.WindowsDefender, "MipDlp.exe", "BlockMDlp.exe"),
(PathLocator.Folders.WindowsDefender, "MpDlpService.exe", "BlockMpDlpService.exe"),
(PathLocator.Folders.WindowsDefender, "mpextms.exe", "Blockmpextms.exe"),
(PathLocator.Folders.WindowsDefender, "NisSrv.exe", "BlockNisSrv.exe"),
@@ -51,7 +53,6 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
(Path.Combine(Environment.SystemDirectory, "HealthAttestationClient"), "HealthAttestationClientAgent.exe", "BlockHACA.exe")
};
-
internal static void SetProtectionState(bool isDisabled)
{
if (isDisabled)
@@ -205,13 +206,11 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
foreach (var (path, normal, block) in fileMappings)
{
- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c rename \"{Path.Combine(path, block)}\" \"{normal}\"");
- }
- foreach (var service in services)
- {
- CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c reg add HKLM\SYSTEM\CurrentControlSet\Services\{service.Key} /v Start /t REG_DWORD /d {service.Value} /f");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""rename ""{Path.Combine(path, block)}"" ""{normal}""""");
}
+ 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")))}""");
+
InvokePowerShell(@"Get-AppXpackage Microsoft.WindowsDefender | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register ""$($_.InstallLocation)\AppXManifest.xml""}");
}
@@ -223,19 +222,27 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
foreach (var (path, normal, block) in fileMappings)
{
- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c rename \"{Path.Combine(path, normal)}\" \"{block}\"");
+ string sourcePath = Path.Combine(path, normal);
+ string targetName = block;
+
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""{CleanCommand(string.Join(" && ", new[] {
+ $@"takeown /f ""{sourcePath}"" /a",
+ $@"icacls ""{sourcePath}"" /inheritance:r",
+ $@"icacls ""{sourcePath}"" /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18",
+ $@"icacls ""{sourcePath}"" /grant ""{Environment.UserName}"":F",
+ $@"rename ""{sourcePath}"" ""{targetName}"""
+ }))}""");
}
- foreach (var service in services)
- {
- CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c reg add HKLM\SYSTEM\CurrentControlSet\Services\{service.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 {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 -ShowWindowMode:Hide -Wait cmd /c " +
+ 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 & " +
$"for /d %D in (\"{Path.Combine(PathLocator.Folders.SystemDrive, @"ProgramData\\Microsoft\\Windows Defender\\Platform\\*")}\") do if exist \"%D\\MpDefenderCoreService.exe\" ren \"%D\\MpDefenderCoreService.exe\" BlockAntimalwareCore.exe & " +
@"reg add HKLM\SYSTEM\CurrentControlSet\Services\WinDefend /v AutorunsDisabled /t REG_DWORD /d 3 /f & " +
@"reg add HKLM\SYSTEM\CurrentControlSet\Services\wscsvc /v DelayedAutoStart /t REG_DWORD /d 1 /f & " +
+ @"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender\Features"" /v TamperProtection /t REG_DWORD /d 0 /f & " +
+ @"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender\Features"" /v TamperProtectionSource /t REG_DWORD /d 2 /f & " +
@"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender\Windows Defender\ControlledFolderAccess"" /v Enable /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\SOFTWARE\Microsoft\Windows defender\CoreService"" /v DisableCoreService1DSTelemetry /t REG_DWORD /d 1 /f & " +
@"reg add ""HKLM\SOFTWARE\Microsoft\Windows defender\CoreService"" /v DisableCoreServiceECSIntegration /t REG_DWORD /d 1 /f & " +
@@ -263,7 +270,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
Set-MpPreference -MAPSReporting 0
Set-MpPreference -PUAProtection Disabled");
- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c " +
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v LocalSettingOverrideDisableOnAccessProtection /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v LocalSettingOverrideRealtimeScanDirection /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection"" /v LocalSettingOverrideDisableIOAVProtection /t REG_DWORD /d 0 /f & " +
@@ -325,7 +332,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Microsoft Antimalware\SpyNet", "SpyNetReporting", 0, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Microsoft Antimalware\SpyNet", "LocalSettingOverrideSpyNetReporting", 0, RegistryValueKind.DWord);
- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c " +
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c " +
@"reg add ""HKLM\Software\Policies\Microsoft\Windows Defender\SpyNet"" /v DisableBlockAtFirstSeen /t REG_DWORD /d 1 /f & " +
@"reg add ""HKLM\Software\Policies\Microsoft\Windows Defender\SpyNet"" /v SpynetReporting /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\Software\Policies\Microsoft\Windows Defender\SpyNet"" /v SubmitSamplesConsent /t REG_DWORD /d 2 /f & " +
@@ -395,11 +402,10 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
RegistryHelp.DeleteValue(Registry.CurrentUser, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Windows Defender");
RegistryHelp.DeleteValue(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "SecurityHealth");
- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c " +
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c " +
@"reg add ""HKCU\Software\Microsoft\Windows\CurrentVersion\AppHost"" /v EnableWebContentEvaluation /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\MicrosoftEdge\PhishingFilter"" /v EnabledV9 /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender"" /v PUAProtection /t REG_DWORD /d 0 /f & " +
- @"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender\Features"" /v TamperProtection /t REG_DWORD /d 0 /f & " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\MRT"" /v DontOfferThroughWUA /t REG_DWORD /d 1 /f & " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\MRT"" /v DontReportInfectionInformation /t REG_DWORD /d 1 /f & " +
@"reg add ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\SmartScreen"" /v ConfigureAppInstallControl /t REG_SZ /d ""Anywhere"" /f & " +
@@ -432,7 +438,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
foreach (var filePath in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly))
{
- CommandExecutor.RunCommandAsTrustedInstaller($"{PathLocator.Executable.NSudo} -U:T -P:E -ShowWindowMode:Hide -Wait cmd /c takeown /f \"{filePath}\" & 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 & rd /s /q \"{filePath}\"");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -M: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 && rd /s /q \""{filePath}\""""");
for (int i = 0; Directory.Exists(filePath) && i < 10; i++)
{
@@ -440,7 +446,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
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 -ShowWindowMode:Hide -Wait cmd /c del /q \"{filePath}\"");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""del /q ""{filePath}""""");
Thread.Sleep(500);
}
@@ -456,7 +462,9 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableVirtualization", 0, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "FilterAdministratorToken", 0, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "PromptOnSecureDesktop", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Run", Path.GetFileNameWithoutExtension(PathLocator.Executable.DisablingWD), $@"""{PathLocator.Executable.DisablingWD}""", RegistryValueKind.String);
+
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "Shell", $"explorer.exe, {PathLocator.Executable.DisablingWD} /unlock", RegistryValueKind.String, true);
+ CommandExecutor.RunCommandAsTrustedInstaller("/c \"bcdedit /set {current} safeboot minimal && shutdown /r /f /t 0\"");
}
private static void ManageExclusions(bool isDisable)
@@ -469,10 +477,10 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
private static void TerminateProcess()
{
- string[] processes = { "smartscreen", "mpdefendercoreservice", "msmpeng", "securityhealthservice", "securityhealthsystray", "securityhealthui", "wuauserv", "searchui", "sechealthui", "configsecuritypolicy", "runtimebroker", "msedge", "ssoncom", "usocoreworker", "defenderbootstrapper", "configsecuritypolicy",
- "dlpuseragent", "lsass", "mpam-d", "mpam-fe", "mpam-fe_bd", "mpas-d", "mpas-fe", "mpas-fe_bd", "mpav-d", "mpav-fe", "mpav-fe_bd", "mpcmdrun", "mpcopyaccelerator", "mpdlpcmd", "mpdlpservice", "mpextms", "mpsigstub", "mrt", "msmpengcp", "mssense", "nissrv", "offlinescannershell", "securekernel", "securityhealthhost",
- "senseap", "senseaptoast", "sensecm", "sensegpparser", "senseidentity", "senseimdscollector", "senseir", "sensendr", "sensesampleuploader", "sensetvm", "sensece", "sgrmbroker", "healthattestationclientagent", "wdnissvc", "wdboot", "msseccore", "mssecflt", "mssecwfp", "mdcoresvc", "sensece", "senseui", "sensepp", "wdsheild" };
- CommandExecutor.RunCommandAsTrustedInstaller($"/c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));
+ string[] processes = { "smartscreen", "mpdefendercoreservice", "msmpeng", "securityhealthservice", "securityhealthsystray", "securityhealthui", "wuauserv", "searchui", "sechealthui", "configsecuritypolicy", "runtimebroker", "msedge", "ssoncom", "usocoreworker", "defenderbootstrapper", "sensedlpprocessor", "sensetracer",
+ "dlpuseragent", "lsass", "mpam-d", "mpam-fe", "mpam-fe_bd", "mpas-d", "mpas-fe", "mpas-fe_bd", "mpav-d", "mpav-fe", "mpav-fe_bd", "mpcmdrun", "mpcopyaccelerator", "mpdlpcmd", "mpdlpservice", "mpextms", "mpsigstub", "mrt", "msmpengcp", "mssense", "nissrv", "offlinescannershell", "securekernel", "usocoreworker", "securityhealthhost",
+ "senseap", "senseaptoast", "sensecm", "sensegpparser", "senseidentity", "senseimdscollector", "senseir", "sensendr", "sensesampleuploader", "sensetvm", "sgrmbroker", "healthattestationclientagent", "wdnissvc", "wdboot", "msseccore", "mssecflt", "mssecwfp", "mdcoresvc", "sensece", "senseui", "sensepp", "wdshield", "mipdlp" };
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));
}
private static void InvokePowerShell(string command)
@@ -495,6 +503,32 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
catch (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.cs
index c3b14214..2d6dd3fd 100644
--- a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
@@ -435,32 +435,22 @@ namespace GTweak.Utilities.Tweaks
{
CommandExecutor.RunCommandAsTrustedInstaller("/c net stop wuauserv & net stop bits & net stop cryptSvc & net stop RuntimeBroker");
- foreach (string name in new[] { "usocoreworker", "RuntimeBroker", "msedge", "MicrosoftEdgeUpdate", "edgeupdate" })
- {
- foreach (Process process in Process.GetProcessesByName(name))
- {
- process.Kill();
- process.WaitForExit(1000);
- }
- }
+ string[] processes = { "usocoreworker", "msedge", "pwahelper", "edgeupdate", "edgeupdatem", "microsoftedgeupdate", "msedgewebviewhost", "msedgeuserbroker", "runtimebroker", "widgets" };
+ CommandExecutor.RunCommandAsTrustedInstaller($"/c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));
foreach (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") })
{
- if (Directory.Exists(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}\"");
+
+ for (int i = 0; Directory.Exists(path) && i < 10; i++)
{
- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{path}\"");
- CommandExecutor.RunCommandAsTrustedInstaller($"/c icacls \"{path}\" /inheritance:r /remove S-1-5-32-544 S-1-5-11 S-1-5-32-545 S-1-5-18");
- CommandExecutor.RunCommandAsTrustedInstaller($"/c icacls \"{path}\" /grant {Environment.UserName}:F");
- CommandExecutor.RunCommandAsTrustedInstaller($"/c rd /s /q \"{path}\"");
+ try { Directory.Delete(path, true); }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- Thread.Sleep(2000);
+ TakingOwnership.GrantAdministratorsAccess(path, TakingOwnership.SE_OBJECT_TYPE.SE_FILE_OBJECT);
+ CommandExecutor.RunCommandAsTrustedInstaller($"/c rd /s /q \"{path}\"");
- if (Directory.Exists(path))
- {
- 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);
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index e3005a63..8ab4bb87 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -288,7 +288,7 @@ namespace GTweak.Utilities.Tweaks
static void RemoveDirectory(string path)
{
- CommandExecutor.RunCommandAsTrustedInstaller($"/c takeown /f \"{path}\" & 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 & rd /s /q \"{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}\"");
for (int i = 0; Directory.Exists(path) && i < 10; i++)
{
@@ -309,6 +309,7 @@ namespace GTweak.Utilities.Tweaks
continue;
}
+ CommandExecutor.RunCommandAsTrustedInstaller("/c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));
RemoveDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft", folder));
}
diff --git a/.Source/GTweak/app.manifest b/.Source/GTweak/app.manifest
index e7d32a72..52f9dd96 100644
--- a/.Source/GTweak/app.manifest
+++ b/.Source/GTweak/app.manifest
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">