From b2e03c375e4a6c5d5f08521f2a4686952630ad21 Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:08:15 +0100 Subject: [PATCH 1/5] Created script for changing the theme (W11 Ready) With this script, it is possible to correctly change the theme of the system and apps in Windows. Ready for Windows 11 (tested) --- stable/ChangeWindowsFullTheme.ps1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 stable/ChangeWindowsFullTheme.ps1 diff --git a/stable/ChangeWindowsFullTheme.ps1 b/stable/ChangeWindowsFullTheme.ps1 new file mode 100644 index 0000000..9ceb908 --- /dev/null +++ b/stable/ChangeWindowsFullTheme.ps1 @@ -0,0 +1,31 @@ +$params = $Input | ConvertFrom-Json + +$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" +$dwordValue = 1 - $(If ($params.themeMode -Eq 0) {$params.daySegment2} Else {$params.themeMode - 1}) + +if (Test-Path $registryPath) { + Set-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -Type DWORD -Force + Set-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -Type DWORD -Force +} + +Add-Type -TypeDefinition @" +using System; +using System.Runtime.InteropServices; + +public class Win32Utils { + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); +} +"@ -PassThru + +$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF +$WM_SETTINGCHANGE = 0x1A +$SPI_SETCLIENTAREAANIMATION = 0x1043 + +# Convertire la stringa "ImmersiveColorSet" in un puntatore +$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") + +$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) + +# Liberare la memoria allocata per la stringa +[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) From 67f193e15923086ec18b745098ed78c7c994b4e4 Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:10:21 +0100 Subject: [PATCH 2/5] Changed comments ChangeWindowsFullTheme.ps1 --- stable/ChangeWindowsFullTheme.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stable/ChangeWindowsFullTheme.ps1 b/stable/ChangeWindowsFullTheme.ps1 index 9ceb908..99733c7 100644 --- a/stable/ChangeWindowsFullTheme.ps1 +++ b/stable/ChangeWindowsFullTheme.ps1 @@ -8,6 +8,7 @@ if (Test-Path $registryPath) { Set-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -Type DWORD -Force } +# Call Windows theme refresh Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; @@ -22,10 +23,8 @@ $HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF $WM_SETTINGCHANGE = 0x1A $SPI_SETCLIENTAREAANIMATION = 0x1043 -# Convertire la stringa "ImmersiveColorSet" in un puntatore $param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") $null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) -# Liberare la memoria allocata per la stringa [System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) From 3fafe0b959e76318b125a65649315a3d8e892b80 Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:15:41 +0100 Subject: [PATCH 3/5] Rename file --- stable/{ChangeWindowsFullTheme.ps1 => ChangeFullWindowsTheme.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stable/{ChangeWindowsFullTheme.ps1 => ChangeFullWindowsTheme.ps1} (100%) diff --git a/stable/ChangeWindowsFullTheme.ps1 b/stable/ChangeFullWindowsTheme.ps1 similarity index 100% rename from stable/ChangeWindowsFullTheme.ps1 rename to stable/ChangeFullWindowsTheme.ps1 From 6882ed7466085e0ec7dabf626283611df3e42921 Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:30:18 +0100 Subject: [PATCH 4/5] Update ChangeFullWindowsTheme.ps1 I integrated the code "fix" made by @t1m0thyj for the other two system and app scripts. This way the script should be usable on both W10 and W11. I cannot test it on W10 so I cannot be sure. --- stable/ChangeFullWindowsTheme.ps1 | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/stable/ChangeFullWindowsTheme.ps1 b/stable/ChangeFullWindowsTheme.ps1 index 99733c7..0b2dc52 100644 --- a/stable/ChangeFullWindowsTheme.ps1 +++ b/stable/ChangeFullWindowsTheme.ps1 @@ -3,28 +3,26 @@ $params = $Input | ConvertFrom-Json $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" $dwordValue = 1 - $(If ($params.themeMode -Eq 0) {$params.daySegment2} Else {$params.themeMode - 1}) -if (Test-Path $registryPath) { - Set-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -Type DWORD -Force - Set-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -Type DWORD -Force +if (Test-Path $registryPath) +{ + New-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null } -# Call Windows theme refresh -Add-Type -TypeDefinition @" +if ([System.Environment]::OSVersion.Version.Build -ge 22000) +{ + # Call Windows theme refresh + Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Win32Utils { [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); } "@ -PassThru -$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF -$WM_SETTINGCHANGE = 0x1A -$SPI_SETCLIENTAREAANIMATION = 0x1043 - -$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") - -$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) - -[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) + $HWND_BROADCAST = [IntPtr]0xFFFF + $WM_SETTINGCHANGE = 0x1A + $SMTO_ABORTIFHUNG = 0x2 + [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero)) +} From e667d8f0a46ad5456d9add5a30e7884d92978f2c Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:34:52 +0100 Subject: [PATCH 5/5] Corrected file I'm so sorry. I had updated the script with the wrong code, the one only for apps --- stable/ChangeFullWindowsTheme.ps1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stable/ChangeFullWindowsTheme.ps1 b/stable/ChangeFullWindowsTheme.ps1 index 0b2dc52..1e0b001 100644 --- a/stable/ChangeFullWindowsTheme.ps1 +++ b/stable/ChangeFullWindowsTheme.ps1 @@ -3,26 +3,26 @@ $params = $Input | ConvertFrom-Json $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" $dwordValue = 1 - $(If ($params.themeMode -Eq 0) {$params.daySegment2} Else {$params.themeMode - 1}) -if (Test-Path $registryPath) -{ - New-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null +if (Test-Path $registryPath) { + Set-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -Type DWORD -Force + Set-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -Type DWORD -Force } if ([System.Environment]::OSVersion.Version.Build -ge 22000) { - # Call Windows theme refresh - Add-Type -TypeDefinition @" + # Call Windows theme refresh + Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Win32Utils { - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); } "@ -PassThru - $HWND_BROADCAST = [IntPtr]0xFFFF - $WM_SETTINGCHANGE = 0x1A - $SMTO_ABORTIFHUNG = 0x2 - [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero)) + $HWND_BROADCAST = [IntPtr]0xFFFF + $WM_SETTINGCHANGE = 0x1A + $SMTO_ABORTIFHUNG = 0x2 + [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero)) }