From b29951514b6f70f7aada6746a2f557086471489e Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 12 Jan 2025 14:48:25 +0300 Subject: [PATCH] Improved StartRecommendedSection function --- .../Module/Sophia.psm1 | 13 ++++++++++--- .../Module/Sophia.psm1 | 18 ++++++++---------- .../Module/Sophia.psm1 | 13 ++++++++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 7fa515b8..06dadf8e 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -4634,9 +4634,9 @@ function StartRecommendedSection $Show ) - # Windows 11 IoT Enterprise not supported - $WINDOWS_LONG = [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") - if (($WINDOWS_LONG -notmatch "Enterprise") -and ($WINDOWS_LONG -notmatch "Education") -or ($WINDOWS_LONG -eq "Windows 11 IoT Enterprise")) + # We cannot call [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") here per this approach does not show a localized Windows edition name + # Windows 11 Home not supported + if ((Get-ComputerInfo).WindowsProductName -match "Home") { Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose @@ -4657,13 +4657,20 @@ function StartRecommendedSection { New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force } + if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education)) + { + New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force + } New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1 } "Show" { Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR } } diff --git a/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 index 221ea80a..cb255fdb 100644 --- a/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 @@ -4476,16 +4476,7 @@ function StartRecommendedSection $Show ) - # Windows 11 IoT Enterprise not supported - $WINDOWS_LONG = [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") - if (($WINDOWS_LONG -notmatch "Enterprise") -and ($WINDOWS_LONG -notmatch "Education") -or ($WINDOWS_LONG -eq "Windows 11 IoT Enterprise")) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose - Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - - return - } + # Windows 11 IoT Enterprise is supported too. No need to check Windows edition # Remove all policies in order to make changes visible in UI only if it's possible Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore @@ -4499,13 +4490,20 @@ function StartRecommendedSection { New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force } + if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education)) + { + New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force + } New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1 } "Show" { Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR } } diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index 8113c4d1..1b1e3f1f 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -4652,9 +4652,9 @@ function StartRecommendedSection $Show ) - # Windows 11 IoT Enterprise not supported - $WINDOWS_LONG = [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") - if (($WINDOWS_LONG -notmatch "Enterprise") -and ($WINDOWS_LONG -notmatch "Education") -or ($WINDOWS_LONG -eq "Windows 11 IoT Enterprise")) + # We cannot call [WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") here per this approach does not show a localized edition name + # Windows 11 Home not supported + if ((Get-ComputerInfo).WindowsProductName -match "Home") { Write-Information -MessageData "" -InformationAction Continue Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose @@ -4675,13 +4675,20 @@ function StartRecommendedSection { New-Item -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Force } + if (-not (Test-Path -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education)) + { + New-Item -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Force + } New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -PropertyType DWord -Value 1 -Force Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type DWORD -Value 1 } "Show" { Remove-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Education -Name IsEducationEnvironment -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start -Name HideRecommendedSection -Force -ErrorAction Ignore Set-Policy -Scope User -Path SOFTWARE\Policies\Microsoft\Windows\Explorer -Name HideRecommendedSection -Type CLEAR } }