@ -301,6 +301,116 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
# Remove harmful blocked DNS domains list from https://github.com/schrebra/Windows.10.DNS.Block.List
Get-NetFirewallRule -DisplayName Block . MSFT * -ErrorAction Ignore | Remove-NetFirewallRule
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript { ( $_ . DisplayName -match " Blocker MicrosoftTelemetry " ) -or ( $_ . DisplayName -match " Blocker MicrosoftExtra " ) -or ( $_ . DisplayName -match " windowsSpyBlocker " ) } | Remove-NetFirewallRule
Write-Information -MessageData " " -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ( [WinAPI.GetStrings] :: GetString ( 12612 ) ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check whether https://github.com is alive
$Parameters = @ {
Uri = " https://github.com "
Method = " Head "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt "
UseBasicParsing = $true
Verbose = $true
}
$extra = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt "
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt "
UseBasicParsing = $true
Verbose = $true
}
$spy = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt "
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt "
UseBasicParsing = $true
Verbose = $true
}
$update = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt "
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = ( Invoke-WebRequest @Parameters ) . Content
$IPArray + = $extra , $extra_v6 , $spy , $spy_v6 , $update , $update_v6
# Split the Array variable content
$IPArray = $IPArray -split " `r ? `n " | Where-Object -FilterScript { $_ -notmatch " # " }
Write-Information -MessageData " " -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ( [WinAPI.GetStrings] :: GetString ( 12612 ) ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ( ( Get-Content -Path " $ env:SystemRoot\System32\drivers\etc\hosts " -Encoding Default -Force | ForEach-Object -Process { $_ . Trim ( ) } | ForEach-Object -Process {
( $_ -ne " " ) -and ( $_ -ne " " ) -and ( -not $_ . StartsWith ( " # " ) ) -and ( $IPArray -split " `r ? `n " | Select-String -Pattern $_ )
} ) -contains $true )
{
Write-Warning -Message ( $Localization . TweakerWarning -f " WindowsSpyBlocker " )
# Clear hosts file
$hosts = Get-Content -Path " $ env:SystemRoot\System32\drivers\etc\hosts " -Encoding Default -Force
$hosts | ForEach-Object -Process {
if ( ( $_ -ne " " ) -and ( -not $_ . StartsWith ( " # " ) ) -and ( $IPArray -split " `r ? `n " | Select-String -Pattern $_ . Trim ( ) ) )
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript { $_ -notmatch $hostsData }
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path " $ env:SystemRoot\System32\drivers\etc\hosts " -Encoding Default -Force
Start-Process -FilePath notepad . exe " $ env:SystemRoot\System32\drivers\etc\hosts "
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://github.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://github.com " ) -ErrorAction SilentlyContinue
}
# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
@ -550,20 +660,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
@ -593,12 +689,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Write-Warning -Message ( $Localization . NoResponse -f " https://github.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://github.com " ) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
}
# Check whether LGPO.exe exists in the bin folder
if ( -not ( Test-Path -Path " $ PSScriptRoot\..\bin\LGPO.exe " ) )
@ -644,20 +734,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
" 19045 "
{
# Check whether the current module version is the latest one
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
try
{
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json
@ -669,17 +745,11 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$LatestSupportedBuild = ( Invoke-RestMethod @Parameters ) . Windows_10
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://github.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://github.com " ) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
$LatestSupportedBuild = 0
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ( $Localization . NoResponse -f " https://github.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://github.com " ) -ErrorAction SilentlyContinue
}
# We may use Test-Path -Path variable:LatestSupportedBuild
@ -709,155 +779,24 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Open the "Windows Update" page
Start-Process -FilePath " ms-settings:windowsupdate "
exit
}
}
}
# Enable back the SysMain service if it was disabled by harmful tweakers
if ( ( Get-Service -Name SysMain ) . Status -eq " Stopped " )
{
Get-Service -Name SysMain | Set-Service -StartupType Automatic
Get-Service -Name SysMain | Start-Service
Write-Verbose -Message " https://www.outsidethebox.ms/19318/ " -Verbose
}
# Automatically manage paging file size for all drives
if ( -not ( Get-CimInstance -ClassName CIM_ComputerSystem ) . AutomaticManagedPageFile )
{
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @ { AutomaticManagedPageFile = $true }
}
# Remove firewalled IP addresses that block Microsoft recourses added by harmful tweakers
# https://wpd.app
Get-NetFirewallRule | Where-Object -FilterScript { ( $_ . DisplayName -match " Blocker MicrosoftTelemetry " ) -or ( $_ . DisplayName -match " Blocker MicrosoftExtra " ) -or ( $_ . DisplayName -match " windowsSpyBlocker " ) } | Remove-NetFirewallRule
Write-Information -MessageData " " -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ( [WinAPI.GetStrings] :: GetString ( 12612 ) ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
# Remove IP addresses from hosts file that block Microsoft recourses added by WindowsSpyBlocker
# https://github.com/crazy-max/WindowsSpyBlocker
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
try
{
# Check whether https://github.com is alive
$Parameters = @ {
Uri = " https://github.com "
Method = " Head "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
return
}
Clear-Variable -Name IPArray -ErrorAction Ignore
# https://github.com/crazy-max/WindowsSpyBlocker/tree/master/data/hosts
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt "
UseBasicParsing = $true
Verbose = $true
}
$extra = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra_v6.txt "
UseBasicParsing = $true
Verbose = $true
}
$extra_v6 = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt "
UseBasicParsing = $true
Verbose = $true
}
$spy = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy_v6.txt "
UseBasicParsing = $true
Verbose = $true
}
$spy_v6 = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update.txt "
UseBasicParsing = $true
Verbose = $true
}
$update = ( Invoke-WebRequest @Parameters ) . Content
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/update_v6.txt "
UseBasicParsing = $true
Verbose = $true
}
$update_v6 = ( Invoke-WebRequest @Parameters ) . Content
$IPArray + = $extra , $extra_v6 , $spy , $spy_v6 , $update , $update_v6
# Split the Array variable content
$IPArray = $IPArray -split " `r ? `n " | Where-Object -FilterScript { $_ -notmatch " # " }
Write-Information -MessageData " " -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ( [WinAPI.GetStrings] :: GetString ( 12612 ) ) -Verbose
Write-Information -MessageData " " -InformationAction Continue
# Check whether hosts contains any of string from $IPArray array
if ( ( Get-Content -Path " $ env:SystemRoot\System32\drivers\etc\hosts " -Encoding Default -Force | ForEach-Object -Process { $_ . Trim ( ) } | ForEach-Object -Process {
( $_ -ne " " ) -and ( $_ -ne " " ) -and ( -not $_ . StartsWith ( " # " ) ) -and ( $IPArray -split " `r ? `n " | Select-String -Pattern $_ )
} ) -contains $true )
{
Write-Warning -Message ( $Localization . TweakerWarning -f " WindowsSpyBlocker " )
# Clear hosts file
$hosts = Get-Content -Path " $ env:SystemRoot\System32\drivers\etc\hosts " -Encoding Default -Force
$hosts | ForEach-Object -Process {
if ( ( $_ -ne " " ) -and ( -not $_ . StartsWith ( " # " ) ) -and ( $IPArray -split " `r ? `n " | Select-String -Pattern $_ . Trim ( ) ) )
{
$hostsData = $_
$hosts = $hosts | Where-Object -FilterScript { $_ -notmatch $hostsData }
}
}
# Save in UTF8 without BOM
$hosts | Set-Content -Path " $ env:SystemRoot\System32\drivers\etc\hosts " -Encoding Default -Force
Start-Process -FilePath notepad . exe " $ env:SystemRoot\System32\drivers\etc\hosts "
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://github.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://github.com " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
exit
}
}
catch [System.ComponentModel.Win32Exception]
}
# Enable back the SysMain service if it was disabled by harmful tweakers
if ( ( Get-Service -Name SysMain ) . Status -eq " Stopped " )
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Get-Service -Name SysMain | Set-Service -StartupType Automatic
Get-Service -Name SysMain | Start-Service
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
Write-Verbose -Message " https://www.outsidethebox.ms/19318/ " -Verbose
}
# Automatically manage paging file size for all drives
if ( -not ( Get-CimInstance -ClassName CIM_ComputerSystem ) . AutomaticManagedPageFile )
{
Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @ { AutomaticManagedPageFile = $true }
}
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
@ -920,7 +859,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
$Menu + = [WinAPI.GetStrings] :: GetString ( 16956 )
}
# Check if current terminal is Windows Terminal
# Check whether current terminal is Windows Terminal
if ( $env:WT_SESSION )
{
# https://github.com/microsoft/terminal/issues/14992
@ -3710,7 +3649,7 @@ public static extern int HashData(byte[] pbData, int cbData, byte[] piet, int ou
}
}
Remove-Item -Path " $ env:SystemRoot\System32\powershell_temp.exe " -Force
Remove-Item -Path " $ env:SystemRoot\System32\WindowsPowerShell\v1.0\ powershell_temp.exe " -Force
}
<#
@ -4738,20 +4677,6 @@ function Cursors
{
" Dark "
{
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
try
{
# Check whether https://github.com is alive
@ -4844,30 +4769,8 @@ function Cursors
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
}
" Light "
{
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
try
{
# Check whether https://github.com is alive
@ -4960,14 +4863,6 @@ function Cursors
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
}
" Default "
{
New-ItemProperty -Path " HKCU:\Control Panel\Cursors " -Name " (default) " -PropertyType String -Value " " -Force
@ -5357,18 +5252,6 @@ public static bool MarkFileDelete (string sourcefile)
{
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveDownloading -Verbose
@ -5407,12 +5290,14 @@ public static bool MarkFileDelete (string sourcefile)
Remove-Item -Path " $ DownloadsFolder\OneDriveSetup.exe " -Force
}
catch [System.ComponentModel.Win32 Exception]
catch [System.Net.Web Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ( $Localization . NoResponse -f " https://download.visualstudio.microsoft.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://download.visualstudio.microsoft.com " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
}
@ -6564,10 +6449,12 @@ function WindowsCapabilities
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " )
Write-Error -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
}
" Uninstall "
@ -9939,7 +9826,7 @@ function UninstallPCHealthCheck
foreach ( $MSI in @ ( Get-ChildItem -Path " $ env:SystemRoot\Installer " -Filter * . msi -File -Force ) )
{
$Name = $Files . Keys | Where-Object -FilterScript { $_ -eq $MSI . Name }
# Check if necessary files exist in folder unless we get a bunch of errors for $File variable
# Check whether necessary files exist in folder unless we get a bunch of errors for $File variable
if ( $Name )
{
$File = $Files [ $Name ]
@ -9978,33 +9865,6 @@ function UninstallPCHealthCheck
function InstallVCRedist
{
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
if ( Get-AppxPackage -Name Microsoft . DesktopAppInstaller )
{
if ( [System.Version] ( Get-AppxPackage -Name Microsoft . DesktopAppInstaller ) . Version -ge [System.Version] " 1.17 " )
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/VCRedist/2015%2B
winget install - -id = Microsoft . VCRedist . 2015 + . x86 - -exact - -force - -accept -source -agreements
winget install - -id = Microsoft . VCRedist . 2015 + . x64 - -exact - -force - -accept -source -agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path " $ env:TEMP\WinGet " -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
{
$DownloadsFolder = Get-ItemPropertyValue -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {374DE290-123F-4565-9164-39C4925E467B} "
$Parameters = @ {
@ -10037,11 +9897,10 @@ function InstallVCRedist
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
catch [System.ComponentModel.Win32Exception]
catch [System.Net.WebException]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ( $Localization . NoResponse -f " https://download.visualstudio.microsoft.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://download.visualstudio.microsoft.com " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
@ -10074,48 +9933,13 @@ function InstallDotNetRuntimes
$Runtimes
)
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
foreach ( $Runtime in $Runtimes )
{
switch ( $Runtime )
{
NET6x64
{
if ( Get-AppxPackage -Name Microsoft . DesktopAppInstaller )
{
if ( [System.Version] ( Get-AppxPackage -Name Microsoft . DesktopAppInstaller ) . Version -ge [System.Version] " 1.17 " )
{
# https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/6
# .NET Desktop Runtime 6 x64
winget install - -id = Microsoft . DotNet . DesktopRuntime . 6 - -architecture x64 - -exact - -force - -accept -source -agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path " $ env:TEMP\WinGet " -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -10126,7 +9950,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = ( Invoke-RestMethod @Parameters ) . " latest-release "
$DownloadsFolder = Get-ItemPropertyValue -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {374DE290-123F-4565-9164-39C4925E467B} "
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://download.visualstudio.microsoft.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://download.visualstudio.microsoft.com " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 6 x64
$Parameters = @ {
Uri = " https://dotnetcli.azureedge.net/dotnet/Runtime/ $ LatestRelease/dotnet-runtime- $ LatestRelease-win-x64.exe "
@ -10135,6 +9971,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://dotnetcli.blob.core.windows.net " )
Write-Error -Message ( $Localization . NoResponse -f " https://dotnetcli.blob.core.windows.net " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath " $ DownloadsFolder\dotnet-runtime- $ LatestRelease-win-x64.exe " -ArgumentList " /install /passive /norestart " -Wait
@ -10146,22 +9992,9 @@ function InstallDotNetRuntimes
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
NET8x64
{
if ( Get-AppxPackage -Name Microsoft . DesktopAppInstaller )
{
if ( [System.Version] ( Get-AppxPackage -Name Microsoft . DesktopAppInstaller ) . Version -ge [System.Version] " 1.17 " )
{
# .NET Desktop Runtime 8 x64
winget install - -id = Microsoft . DotNet . DesktopRuntime . 8 - -architecture x64 - -exact - -force - -accept -source -agreements
# PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word
# https://github.com/PowerShell/PowerShell/issues/21070
Get-ChildItem -Path " $ env:TEMP\WinGet " -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
}
}
else
try
{
# .NET Desktop Runtime 8
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
@ -10172,7 +10005,19 @@ function InstallDotNetRuntimes
}
$LatestRelease = ( Invoke-RestMethod @Parameters ) . " latest-release "
$DownloadsFolder = Get-ItemPropertyValue -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {374DE290-123F-4565-9164-39C4925E467B} "
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json " )
Write-Error -Message ( $Localization . NoResponse -f " https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
try
{
# .NET Desktop Runtime 8 x64
$Parameters = @ {
Uri = " https://dotnetcli.azureedge.net/dotnet/Runtime/ $ LatestRelease/dotnet-runtime- $ LatestRelease-win-x64.exe "
@ -10181,6 +10026,16 @@ function InstallDotNetRuntimes
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://dotnetcli.blob.core.windows.net " )
Write-Error -Message ( $Localization . NoResponse -f " https://dotnetcli.blob.core.windows.net " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
Start-Process -FilePath " $ DownloadsFolder\dotnet-runtime- $ LatestRelease-win-x64.exe " -ArgumentList " /install /passive /norestart " -Wait
@ -10194,7 +10049,6 @@ function InstallDotNetRuntimes
}
}
}
}
}
<#
@ -10510,20 +10364,6 @@ function RegistryBackup
#>
function Install-WSL
{
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
try
{
# https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json
@ -10539,6 +10379,16 @@ function Install-WSL
" Alias " = $_ . Name
}
}
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json " )
Write-Error -Message ( $Localization . NoResponse -f " https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
Add-Type -AssemblyName PresentationCore , PresentationFramework
@ -10662,18 +10512,6 @@ function Install-WSL
# Force move the WPF form to the foreground
$Window . Add_Loaded ( { $Window . Activate ( ) } )
$Form . ShowDialog ( ) | Out-Null
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " https://raw.githubusercontent.com " )
Write-Error -Message ( $Localization . NoResponse -f " https://raw.githubusercontent.com " ) -ErrorAction SilentlyContinue
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
}
}
#endregion WSL
@ -11589,29 +11427,6 @@ function HEVC
return
}
try
{
# Check the internet connection
$Parameters = @ {
Name = " dns.msftncsi.com "
Server = " 1.1.1.1 "
DnsOnly = $true
ErrorAction = " Stop "
}
if ( ( Resolve-DnsName @Parameters ) . IPAddress -notcontains " 131.107.255.255 " )
{
return
}
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
switch ( $PSCmdlet . ParameterSetName )
{
" Install "
@ -11654,6 +11469,19 @@ function HEVC
# Installing "HEVC Video Extensions from Device Manufacturer"
if ( [System.Version] $HEVCPackageName -gt [System.Version] ( Get-AppxPackage -Name Microsoft . HEVCVideoExtension ) . Version )
{
try
{
# Check whether https://store.rg-adguard.net is alive
$Parameters = @ {
Uri = $TempURL
UseBasicParsing = $true
Verbose = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
return
}
Write-Information -MessageData " " -InformationAction Continue
# Extract the localized "Please wait..." string from shell32.dll
Write-Verbose -Message ( [WinAPI.GetStrings] :: GetString ( 12612 ) ) -Verbose
@ -11672,6 +11500,16 @@ function HEVC
Add-AppxPackage -Path " $ DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx " -Verbose
Remove-Item -Path " $ DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx " -Force
}
catch [System.Net.WebException]
{
Write-Warning -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " )
Write-Error -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
}
else
{
Write-Information -MessageData " " -InformationAction Continue
@ -11684,6 +11522,8 @@ function HEVC
Write-Error -Message ( $Localization . NoResponse -f " https://store.rg-adguard.net/api/GetFiles " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
return
}
}
" Manually "
@ -13713,7 +13553,7 @@ function WindowsScriptHost
{
" Disable "
{
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
# Check whether any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution , Temp , " Windows Cleanup " , " Windows Cleanup Notification " -ErrorAction Ignore | ForEach-Object -Process {
# Skip if a scheduled task exists
if ( $_ . State -eq " Ready " )
@ -13803,6 +13643,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization . EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
}
}
@ -13826,6 +13667,7 @@ function WindowsSandbox
catch [System.Exception]
{
Write-Error -Message $Localization . EnableHardwareVT -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
}
}
@ -13878,7 +13720,7 @@ function DNSoverHTTPS
[ Parameter ( Mandatory = $false ) ]
[ ValidateSet ( " 1.0.0.1 " , " 1.1.1.1 " , " 149.112.112.112 " , " 8.8.4.4 " , " 8.8.8.8 " , " 9.9.9.9 " ) ]
[ ValidateScript ( {
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $SecondaryDNS
} ) ]
[string]
@ -13887,7 +13729,7 @@ function DNSoverHTTPS
[ Parameter ( Mandatory = $false ) ]
[ ValidateSet ( " 1.0.0.1 " , " 1.1.1.1 " , " 149.112.112.112 " , " 8.8.4.4 " , " 8.8.8.8 " , " 9.9.9.9 " ) ]
[ ValidateScript ( {
# Check if $PrimaryDNS is not equal to $SecondaryDNS
# Check whether $PrimaryDNS is not equal to $SecondaryDNS
$_ -ne $PrimaryDNS
} ) ]
[string]
@ -14541,8 +14383,8 @@ function BitmapImageNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " )
Write-Error -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
@ -14632,8 +14474,8 @@ function RichTextDocumentNewContext
}
catch [System.ComponentModel.Win32Exception]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Warning -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " )
Write-Error -Message ( $Localization . NoResponse -f " http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line . Trim ( ) ) -ErrorAction SilentlyContinue
}
@ -14816,7 +14658,7 @@ function UseStoreOpenWith
<#
. SYNOPSIS
Display all policy registry keys ( even manually created ones ) in the Local Group Policy Editor snap-in ( gpedit . msc )
This can take up to 30 minutes , depending on on the number of policies created in the registry and your system resources
This can take up to 30 minutes , depending on the number of policies created in the registry and your system resources
. EXAMPLE
UpdateLGPEPolicies
@ -14847,6 +14689,8 @@ function UpdateLGPEPolicies
Write-Verbose -Message ( [WinAPI.GetStrings] :: GetString ( 12612 ) ) -Verbose
Write-Verbose -Message $Localization . GPOUpdate -Verbose
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message HKLM -Verbose
Write-Information -MessageData " " -InformationAction Continue
@ -14907,6 +14751,7 @@ function UpdateLGPEPolicies
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message HKCU -Verbose
Write-Information -MessageData " " -InformationAction Continue
# Current User policies paths to scan recursively
$CU_Paths = @ (