Skip to content

Portable Tool for an Ideal Windows Setup

fix grant temporary access for renaming and clean up ACLs

Greedeks19554be49f57
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index f66584f7..2cffc323 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -154,7 +154,7 @@
<Compile Include="Utilities\Maintenance\ClearingMemory.cs" />
<Compile Include="Utilities\Maintenance\RegistryExporter.cs" />
<Compile Include="Utilities\Tweaks\ConfidentialityTweaks.cs" />
- <Compile Include="Utilities\Tweaks\DefenderManager\BackupRights.cs" />
+ <Compile Include="Utilities\Tweaks\DefenderManager\AclPermissionsBackup.cs" />
<Compile Include="Utilities\Tweaks\DefenderManager\WindowsDefender.cs" />
<Compile Include="Utilities\Tweaks\InterfaceTweaks.cs" />
<Compile Include="Utilities\Maintenance\NTFSCompressor.cs" />
diff --git a/.Source/GTweak/Resources/DisablingWD.gz b/.Source/GTweak/Resources/DisablingWD.gz
index 932bf8e3..c480f4db 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 9b784f44..f1a96ccb 100644
--- a/.Source/GTweak/Utilities/Controls/PathLocator.cs
+++ b/.Source/GTweak/Utilities/Controls/PathLocator.cs
@@ -320,9 +320,9 @@ namespace GTweak.Utilities.Controls
internal static readonly string ErrorLog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GTweak_Error.log");
- internal static readonly string BackupDataJson = Path.Combine(Folders.DefenderBackup, "BackupData.json");
+ internal static readonly string BackupJsonWD = Path.Combine(Folders.DefenderBackup, "BackupData.json");
- internal static readonly string BackupRightsAcl = Path.Combine(Folders.DefenderBackup, "BackupRights.acl");
+ internal static readonly string BackupAclWD = Path.Combine(Folders.DefenderBackup, "AclBackup.acl");
}
internal static class Registry
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs
similarity index 95%
rename from .Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
rename to .Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs
index 6a586826..9c96074c 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/BackupRights.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs
@@ -10,7 +10,7 @@ using Newtonsoft.Json.Linq;
namespace GTweak.Utilities.Tweaks.DefenderManager
{
- internal class BackupRights : TaskSchedulerManager
+ internal class AclPermissionsBackup : TaskSchedulerManager
{
private static readonly Dictionary<string, RegistryHive> _storageRegPaths = new Dictionary<string, RegistryHive>
{
@@ -93,14 +93,6 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
internal object Value { get; set; }
}
- private class FileRightsInfo
- {
- internal string OriginalPath { get; set; }
- internal string Owner { get; set; }
- internal string Permissions { get; set; }
- internal string Sddl { get; set; }
- }
-
internal static void ExportRights()
{
try
@@ -177,20 +169,20 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
}
}
- File.WriteAllText(PathLocator.Files.BackupDataJson, JsonConvert.SerializeObject(allValues, Formatting.Indented));
- File.WriteAllText(PathLocator.Files.BackupRightsAcl, JsonConvert.SerializeObject(aclDataDict, Formatting.Indented));
+ File.WriteAllText(PathLocator.Files.BackupJsonWD, JsonConvert.SerializeObject(allValues, Formatting.Indented));
+ File.WriteAllText(PathLocator.Files.BackupAclWD, 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))
+ if (File.Exists(PathLocator.Files.BackupJsonWD) && File.Exists(PathLocator.Files.BackupAclWD))
{
try
{
- Dictionary<string, Dictionary<string, RegistryValueBackup>> allValues = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, RegistryValueBackup>>>(File.ReadAllText(PathLocator.Files.BackupDataJson));
- Dictionary<string, string> aclDataDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(PathLocator.Files.BackupRightsAcl));
+ Dictionary<string, Dictionary<string, RegistryValueBackup>> allValues = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, RegistryValueBackup>>>(File.ReadAllText(PathLocator.Files.BackupJsonWD));
+ Dictionary<string, string> aclDataDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(PathLocator.Files.BackupAclWD));
if (allValues == null)
{
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
index a5a622f3..948f10f0 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
@@ -12,7 +12,7 @@ using Microsoft.Win32;
namespace GTweak.Utilities.Tweaks.DefenderManager
{
- internal class WindowsDefender : BackupRights
+ internal class WindowsDefender : AclPermissionsBackup
{
private static readonly Dictionary<string, string> services = new Dictionary<string, string>
{
@@ -109,6 +109,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
@"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 & " +
+ @"reg add ""HKLM\SOFTWARE\Microsoft\Windows Defender\Features"" /v TamperProtection /t REG_DWORD /d 1 /f & " +
@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\MRT"" /v DontOfferThroughWUA /f & " +
@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\MRT"" /v DontReportInfectionInformation /f & " +
@"reg delete ""HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\SmartScreen"" /v ConfigureAppInstallControl /f & " +
@@ -143,12 +144,12 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Policies\Microsoft\Windows Defender", "DisableRoutinelyTakingAction", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\CI\Policy", "VerifiedAndReputablePolicyState", 1, RegistryValueKind.DWord);
-
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\MicrosoftEdge\PhishingFilter");
+
+ RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\CI\Policy", "VerifiedAndReputablePolicyState", 1, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\CI\Config", "VulnerableDriverBlocklistEnable", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"System\CurrentControlSet\Control\CI\State", "HVCIEnabled", 1, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\CI\Config", "EnabledV9", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"System\CurrentControlSet\Control\CI\State", "HVCIEnabled", 1, RegistryValueKind.DWord);
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\WTDS");
RegistryHelp.DeleteValue(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity", "Enabled");
RegistryHelp.DeleteValue(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\DeviceGuard", "EnableVirtualizationBasedSecurity");
@@ -196,7 +197,21 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
foreach (var (path, normal, block) in fileMappings)
{
- CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -M:S -ShowWindowMode:Hide -Wait cmd /c ""rename ""{Path.Combine(path, block)}"" ""{normal}""""");
+ 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[] {
+ $@"takeown /f ""{sourcePath}"" /a",
+ $@"rename ""{sourcePath}"" ""{normal}""",
+ $@"icacls ""{targetPath}"" /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",
+ $@"icacls ""{targetPath}"" /inheritance:r",
+ $@"icacls ""{targetPath}"" /grant *S-1-5-32-544:F",
+ $@"icacls ""{targetPath}"" /grant *S-1-5-32-545:R",
+ $@"icacls ""{targetPath}"" /grant *S-1-5-18:F",
+ $@"icacls ""{targetPath}"" /grant *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464:F",
+ $@"icacls ""{targetPath}"" /grant *S-1-15-2-1:R",
+ $@"icacls ""{targetPath}"" /grant *S-1-15-2-2:R",
+ $@"icacls ""{targetPath}"" /remove ""{Environment.UserName}"""}))}""");
}
ImportRights();
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index b9a28ddf..c424cd3a 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -107,8 +107,8 @@ namespace GTweak.Utilities.Tweaks
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- _с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[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] =
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power", "HiberbootEnabled", "0") ||
@@ -140,8 +140,9 @@ 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") &&
- !RegistryHelp.GetValue($@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\{_currentPowerGuid}", "FriendlyName", string.Empty).Contains("-19");
+ _с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;
@@ -249,6 +250,7 @@ namespace GTweak.Utilities.Tweaks
BlockWDefender(isDisabled);
ArchiveManager.Unarchive(PathLocator.Executable.NSudo, Properties.Resources.NSudoLC);
ArchiveManager.Unarchive(PathLocator.Executable.DisablingWD, Properties.Resources.DisablingWD);
+
if (canShowWindow)
{
OverlayWindow overlayWindow = new OverlayWindow();