From 5e108835479fe8b10570efcdd904630ff7e1aaf4 Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Thu, 6 Jun 2024 11:33:39 -0500 Subject: [PATCH 1/6] Fix Numlock toggle (#2044) * Fix Numlock at login * Compile Winutil --------- Co-authored-by: ChrisTitusTech --- functions/private/Invoke-WinUtilNumLock.ps1 | 2 +- winutil.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/private/Invoke-WinUtilNumLock.ps1 b/functions/private/Invoke-WinUtilNumLock.ps1 index 9f62b22a..64fe4110 100644 --- a/functions/private/Invoke-WinUtilNumLock.ps1 +++ b/functions/private/Invoke-WinUtilNumLock.ps1 @@ -15,7 +15,7 @@ function Invoke-WinUtilNumLock { Write-Host "Disabling Numlock on startup" $value = 0 } - $Path = "HKCU:\Control Panel\Keyboard" + $Path = "HKU:\.Default\Control Panel\Keyboard" Set-ItemProperty -Path $Path -Name InitialKeyboardIndicators -Value $value } Catch [System.Security.SecurityException] { diff --git a/winutil.ps1 b/winutil.ps1 index d8d080c6..ab162c15 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -1987,7 +1987,7 @@ function Invoke-WinUtilNumLock { Write-Host "Disabling Numlock on startup" $value = 0 } - $Path = "HKCU:\Control Panel\Keyboard" + $Path = "HKU:\.Default\Control Panel\Keyboard" Set-ItemProperty -Path $Path -Name InitialKeyboardIndicators -Value $value } Catch [System.Security.SecurityException] { From 02ea93c80fb209a47c3ed55675923962def70821 Mon Sep 17 00:00:00 2001 From: ChrisTitusTech Date: Thu, 6 Jun 2024 16:34:06 +0000 Subject: [PATCH 2/6] Compile Winutil --- winutil.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winutil.ps1 b/winutil.ps1 index ab162c15..56c75377 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -10,7 +10,7 @@ Author : Chris Titus @christitustech Runspace Author: @DeveloperDurp GitHub : https://github.com/ChrisTitusTech - Version : 24.06.05 + Version : 24.06.06 #> param ( [switch]$Debug, @@ -47,7 +47,7 @@ Add-Type -AssemblyName System.Windows.Forms # Variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot -$sync.version = "24.06.05" +$sync.version = "24.06.06" $sync.configs = @{} $sync.ProcessRunning = $false From 774b64b0921c63557a1262f3f9b9b398140814a5 Mon Sep 17 00:00:00 2001 From: nikolan <94351312+nikolan123@users.noreply.github.com> Date: Thu, 6 Jun 2024 09:35:12 -0700 Subject: [PATCH 3/6] fix typo (#2041) --- config/tweaks.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/tweaks.json b/config/tweaks.json index 775f0f1b..709ef1d3 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -2394,7 +2394,7 @@ ], "InvokeScript": [ " - Write-Host \"Remove Popilot\" + Write-Host \"Remove Copilot\" dism /online /remove-package /package-name:Microsoft.Windows.Copilot " ], @@ -3084,4 +3084,4 @@ "Order": "a082_", "Type": "300" } -} \ No newline at end of file +} From 7b6decb28aadb2c6e87f687952c307660320e822 Mon Sep 17 00:00:00 2001 From: ChrisTitusTech Date: Thu, 6 Jun 2024 16:35:38 +0000 Subject: [PATCH 4/6] Compile Winutil --- winutil.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winutil.ps1 b/winutil.ps1 index 56c75377..dab68f20 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -10950,7 +10950,7 @@ $sync.configs.tweaks = '{ ], "InvokeScript": [ " - Write-Host \"Remove Popilot\" + Write-Host \"Remove Copilot\" dism /online /remove-package /package-name:Microsoft.Windows.Copilot " ], From 3dca1ee43ec5b5d5a320fff98c31ba642e3f23b7 Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Thu, 6 Jun 2024 11:39:49 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a921ad79..c8b43b54 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,9 @@ If you encounter any challenges or problems with the script, I kindly request th ## Contribute Code -To contribute new code, please ensure that it is submitted to the **TEST BRANCH**. Please note that merges will not be performed directly on the MAIN branch. +If you adding, changing, or deleting an Application... submit to **APPLICATIONS branch**. We batch these in at the end of the month. + +If doing a code change and you can submit a PR to main branch, but I am very selective about these. Do not use a code formatter, massive amounts of line changes, and make multiple feature changes. EACH FEATURE CHANGE SHOULD BE IT'S OWN Pull Request! When creating pull requests, it is essential to thoroughly document all changes made. This includes documenting any additions made to the tweaks section and ensuring that corresponding undo measures are in place to remove the newly added tweaks if necessary. Failure to adhere to this format may result in denial of the pull request. Additionally, comprehensive documentation is required for all code changes. Any code lacking sufficient documentation may also be denied. From 706f73923ab54c677c36d65457c019c9e4fa7471 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Fri, 7 Jun 2024 01:01:48 +0200 Subject: [PATCH 6/6] Modify DNS ComboBox - Replaced "Default" with "Custom" - Set Default Dropdown Content to applied option or "Custom" if not in the list. - saves custom IPs on multiple adapters > If user sets DNS to Cloudflare and runs the tweaks but wants to undo it before he closed the script he can select "custom" and run it to apply the saved addresses --- config/tweaks.json | 3 +- functions/private/Get-WinUtilDNS.ps1 | 70 ++++++++++++++++++++++++++++ functions/private/Set-WinUtilDNS.ps1 | 27 ++++++++--- scripts/main.ps1 | 2 + xaml/inputTweaks.xaml | 2 +- 5 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 functions/private/Get-WinUtilDNS.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index 709ef1d3..afd3cd8d 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -3043,11 +3043,12 @@ }, "WPFchangedns": { "Content": "DNS", + "Name": "DNS", "category": "z__Advanced Tweaks - CAUTION", "panel": "1", "Order": "a040_", "Type": "Combobox", - "ComboItems": "Default DHCP Google Cloudflare Cloudflare_Malware Cloudflare_Malware_Adult Level3 Open_DNS Quad9" + "ComboItems": "Custom DHCP Google Cloudflare Cloudflare_Malware Cloudflare_Malware_Adult Level3 Open_DNS Quad9" }, "WPFTweaksbutton": { "Content": "Run Tweaks", diff --git a/functions/private/Get-WinUtilDNS.ps1 b/functions/private/Get-WinUtilDNS.ps1 new file mode 100644 index 00000000..3f48fabb --- /dev/null +++ b/functions/private/Get-WinUtilDNS.ps1 @@ -0,0 +1,70 @@ +function Get-WinUtilDNS { + <# + + .SYNOPSIS + Gets the DNS of all interfaces that are in the "Up" state. It will set the default state of the ComboBox to the DNS provider that is currently set on the interface. + + #> + + Try { + $Adapters = Get-NetAdapter | Where-Object {$_.Status -eq "Up"} + + # Get all DNS providers and their server addresses + $dnsProviders = $sync.configs.dns.PSObject.Properties | ForEach-Object { + @{ + Name = $_.Name + Primary = $_.Value.Primary + Secondary = $_.Value.Secondary + } + } + + # Initialize a variable to hold the matched provider + $matchedProvider = $null + $global:previousDnsSettings = @() + + Foreach ($Adapter in $Adapters) { + Try { + # Get the current DNS server addresses + $currentDnsServers = (Get-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -AddressFamily IPv4).ServerAddresses + + # Save the current DNS server addresses + $global:previousDnsSettings += @{ + AdapterName = $Adapter.Name + DnsAddresses = $currentDnsServers + } + + # Check if the current DNS servers match any of the providers + $matchingProvider = $dnsProviders | Where-Object { + $currentDnsServers -contains $_.Primary -and $currentDnsServers -contains $_.Secondary + } + + if ($matchingProvider) { + # If this is the first match, set the matchedProvider + if (-not $matchedProvider) { + $matchedProvider = $matchingProvider.Name + } elseif ($matchedProvider -ne $matchingProvider.Name) { + # If there is a mismatch in providers, set to Custom + $matchedProvider = "Custom" + break + } + } else { + # If no match is found, set to Custom + $matchedProvider = "Custom" + break + } + } Catch { + Write-Warning "Failed to process adapter: $($Adapter.Name)" + Write-Warning $_.Exception.Message + Write-Warning $_.Exception.StackTrace + } + } + + # Set the text of $sync["WPFchangedns"] to the result text + $sync["WPFchangedns"].text = if ($matchedProvider) { $matchedProvider } else { "Custom" } + } + Catch { + Write-Warning "Unable to get DNS Provider due to an unhandled exception" + Write-Warning $_.Exception.Message + Write-Warning $_.Exception.StackTrace + } +} diff --git a/functions/private/Set-WinUtilDNS.ps1 b/functions/private/Set-WinUtilDNS.ps1 index 314a5ac8..d35739f4 100644 --- a/functions/private/Set-WinUtilDNS.ps1 +++ b/functions/private/Set-WinUtilDNS.ps1 @@ -12,23 +12,36 @@ function Set-WinUtilDNS { #> param($DNSProvider) - if($DNSProvider -eq "Default"){return} + + $dnsProviders = $sync.configs.dns.PSObject.Properties.Name + Try{ $Adapters = Get-NetAdapter | Where-Object {$_.Status -eq "Up"} Write-Host "Ensuring DNS is set to $DNSProvider on the following interfaces" Write-Host $($Adapters | Out-String) Foreach ($Adapter in $Adapters){ - if($DNSProvider -eq "DHCP"){ - Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ResetServerAddresses - } - Else{ - Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses ("$($sync.configs.dns.$DNSProvider.Primary)", "$($sync.configs.dns.$DNSProvider.Secondary)") + switch ($DNSProvider) { + "DHCP" { + Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ResetServerAddresses + } + "Custom" { + $savedSettings = $global:previousDnsSettings | Where-Object { $_.AdapterName -eq $Adapter.Name } + + if ($savedSettings) { + # Set the DNS server addresses for the adapter to the saved addresses + Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses $savedSettings.DnsAddresses + } + } + default { + Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses ("$($sync.configs.dns.$DNSProvider.Primary)", "$($sync.configs.dns.$DNSProvider.Secondary)") + } } } } Catch{ Write-Warning "Unable to set DNS Provider due to an unhandled exception" - Write-Warning $psitem.Exception.StackTrace + Write-Warning $_.Exception.Message + Write-Warning $_.Exception.StackTrace } } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 23978ab7..66e49252 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -434,6 +434,8 @@ $sync["CheckboxFilter"].Add_TextChanged({ $label.Visibility = "Collapsed"} }) +Get-WinUtilDNS + # Define event handler for button click $sync["SettingsButton"].Add_Click({ Write-Debug "SettingsButton clicked" diff --git a/xaml/inputTweaks.xaml b/xaml/inputTweaks.xaml index 8bae8e92..d750a4ea 100644 --- a/xaml/inputTweaks.xaml +++ b/xaml/inputTweaks.xaml @@ -40,7 +40,7 @@