From be96db875bc0dfb634c3c9dfec220889fe139b9d Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 20 Oct 2024 15:46:52 +0300 Subject: [PATCH] Update Sophia.psm1 --- Download_Sophia.ps1 | 22 +- .../en-US/tooltip_Windows_10.json | 2 +- .../en-US/tooltip_Windows_11.json | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 1201 +++++++---------- src/Sophia_Script_for_Windows_10/Sophia.ps1 | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 915 ++++++------- .../Sophia.ps1 | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 1099 +++++++-------- .../Sophia.ps1 | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Manifest/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 1201 +++++++---------- .../Sophia.ps1 | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 1111 +++++++-------- src/Sophia_Script_for_Windows_11/Sophia.ps1 | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 1107 +++++++-------- .../Sophia.ps1 | 2 +- .../Localizations/uk-UA/Sophia.psd1 | 2 +- .../Manifest/Sophia.psd1 | 2 +- .../Module/Sophia.psm1 | 1133 +++++++--------- .../Sophia.ps1 | 2 +- 26 files changed, 3395 insertions(+), 4430 deletions(-) diff --git a/Download_Sophia.ps1 b/Download_Sophia.ps1 index 2de44144a..a9c7b02d7 100644 --- a/Download_Sophia.ps1 +++ b/Download_Sophia.ps1 @@ -49,7 +49,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) Verbose = $true } - $Version = "LTSC2019" + $Version = "Windows_10_LTSC2019" } else { @@ -79,7 +79,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) UseBasicParsing = $true Verbose = $true } - $Version = "LTSC2021" + $Version = "Windows_10_LTSC2021" } else { @@ -163,7 +163,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) Verbose = $true } - $Version = "LTSC2024" + $Version = "Windows_11_LTSC2024" } } } @@ -176,10 +176,10 @@ if (-not (Test-Path -Path "$DownloadsFolder\Sophia.Script.zip")) # Check for updates Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - # Open the "Windows Update" page + # Open t"Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" - return + exit } $Parameters = @{ @@ -195,23 +195,25 @@ Start-Sleep -Second 1 switch ($Version) { - "LTSC2019" + "Windows_10_LTSC2019" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2019_v$LatestRelease" + if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) { Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2019_v$LatestRelease" } } - "LTSC2021" + "Windows_10_LTSC2021" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2021_v$LatestRelease" + if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) { Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_LTSC_2021_v$LatestRelease" } } - "LTSC2024" + "Windows_11_LTSC2024" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_LTSC_2024_v$LatestRelease" if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) @@ -222,6 +224,7 @@ switch ($Version) "Windows_10_PowerShell_5.1" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_v$LatestRelease" + if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) { Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_v$LatestRelease" @@ -230,6 +233,7 @@ switch ($Version) "Windows_10_PowerShell_7" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_PowerShell_7_v$LatestRelease" + if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) { Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_10_PowerShell_7_v$LatestRelease" @@ -238,6 +242,7 @@ switch ($Version) "Windows_11_PowerShell_5.1" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_v$LatestRelease" + if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) { Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_v$LatestRelease" @@ -246,6 +251,7 @@ switch ($Version) "Windows_11_PowerShell_7" { Invoke-Item -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_PowerShell_7_v$LatestRelease" + if ((([System.Security.Principal.WindowsIdentity]::GetCurrent()).Owner -eq "S-1-5-32-544")) { Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_PowerShell_7_v$LatestRelease" diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_10.json b/Wrapper/Localizations/en-US/tooltip_Windows_10.json index 6738c2150..07e9b2dc5 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_10.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_10.json @@ -2084,7 +2084,7 @@ "Arg": { "Zero": { "Tag": "", - "ToolTip": "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." + "ToolTip": "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 the number of policies created in the registry and your system resources." } } } diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_11.json b/Wrapper/Localizations/en-US/tooltip_Windows_11.json index 09deb71e8..82edc77b5 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_11.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_11.json @@ -1955,7 +1955,7 @@ "Arg": { "Zero": { "Tag": "", - "ToolTip": "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." + "ToolTip": "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 the number of policies created in the registry and your system resources." } } } diff --git a/src/Sophia_Script_for_Windows_10/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_10/Localizations/uk-UA/Sophia.psd1 index 6bbba9167..ecef3b250 100644 --- a/src/Sophia_Script_for_Windows_10/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_10/Localizations/uk-UA/Sophia.psd1 @@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 06bd477ae..fae8c07f2 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -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 @@ -552,52 +662,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_PowerShell_5_1 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_PowerShell_5_1 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether LGPO.exe exists in the bin folder @@ -646,40 +736,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -729,137 +799,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -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 } <# @@ -4740,114 +4679,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } + + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force + } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - } + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4856,114 +4773,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } + + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force + } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - } + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -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.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 + + 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] @@ -9979,69 +9866,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $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 + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } + Invoke-WebRequest @Parameters - 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 + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait - - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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,33 +9971,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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,17 +10026,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -10512,42 +10366,38 @@ function Install-WSL { try { - # Check the internet connection + # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json + # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" + UseBasicParsing = $true + Verbose = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") - { - return + $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + [PSCustomObject]@{ + "Distribution" = $_.FriendlyName + "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 - try - { - # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json - # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" - UseBasicParsing = $true - Verbose = $true - } - $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { - [PSCustomObject]@{ - "Distribution" = $_.FriendlyName - "Alias" = $_.Name - } - } + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } - Add-Type -AssemblyName PresentationCore, PresentationFramework + Add-Type -AssemblyName PresentationCore, PresentationFramework - #region Variables - $CommandTag = $null + #region Variables + $CommandTag = $null - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" + #region XAML Markup + # The section defines the design of the upcoming dialog box + [xml]$XAML = @" "@ - #endregion XAML Markup - - $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) - $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) - } + #endregion XAML Markup - $ButtonInstall.Content = $Localization.Install - #endregion Variables + $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) + $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) + } - #region Functions - function RadioButtonChecked - { - $Script:CommandTag = $_.OriginalSource.Tag - if (-not $ButtonInstall.IsEnabled) - { - $ButtonInstall.IsEnabled = $true - } - } + $ButtonInstall.Content = $Localization.Install + #endregion Variables - function ButtonInstallClicked - { - Write-Warning -Message $Script:CommandTag + #region Functions + function RadioButtonChecked + { + $Script:CommandTag = $_.OriginalSource.Tag + if (-not $ButtonInstall.IsEnabled) + { + $ButtonInstall.IsEnabled = $true + } + } - Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait + function ButtonInstallClicked + { + Write-Warning -Message $Script:CommandTag - $Form.Close() + Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait - # Receive updates for other Microsoft products when you update Windows - (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") + $Form.Close() - # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - } - #endregion + # Receive updates for other Microsoft products when you update Windows + (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") - foreach ($Distribution in $Distributions) - { - $Panel = New-Object -TypeName System.Windows.Controls.StackPanel - $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton - $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock - $Panel.Orientation = "Horizontal" - $RadioButton.GroupName = "WslDistribution" - $RadioButton.Tag = $Distribution.Alias - $RadioButton.Add_Checked({RadioButtonChecked}) - $TextBlock.Text = $Distribution.Distribution - $Panel.Children.Add($RadioButton) | Out-Null - $Panel.Children.Add($TextBlock) | Out-Null - $PanelContainer.Children.Add($Panel) | Out-Null - } + # Check for updates + Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + } + #endregion - $ButtonInstall.Add_Click({ButtonInstallClicked}) + foreach ($Distribution in $Distributions) + { + $Panel = New-Object -TypeName System.Windows.Controls.StackPanel + $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton + $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock + $Panel.Orientation = "Horizontal" + $RadioButton.GroupName = "WslDistribution" + $RadioButton.Tag = $Distribution.Alias + $RadioButton.Add_Checked({RadioButtonChecked}) + $TextBlock.Text = $Distribution.Distribution + $Panel.Children.Add($RadioButton) | Out-Null + $Panel.Children.Add($TextBlock) | Out-Null + $PanelContainer.Children.Add($Panel) | Out-Null + } - #region Sendkey function - # Emulate the Backspace key sending to prevent the console window to freeze - Start-Sleep -Milliseconds 500 + $ButtonInstall.Add_Click({ButtonInstallClicked}) - Add-Type -AssemblyName System.Windows.Forms + #region Sendkey function + # Emulate the Backspace key sending to prevent the console window to freeze + Start-Sleep -Milliseconds 500 - # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID - Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10")} | ForEach-Object -Process { - # Show window, if minimized - [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) + Add-Type -AssemblyName System.Windows.Forms - Start-Sleep -Seconds 1 + # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID + Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10")} | ForEach-Object -Process { + # Show window, if minimized + [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) - # Force move the console window to the foreground - [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) + Start-Sleep -Seconds 1 - Start-Sleep -Seconds 1 + # Force move the console window to the foreground + [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) - # Emulate the Backspace key sending - [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") - } - #endregion Sendkey function + Start-Sleep -Seconds 1 - # 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 + # Emulate the Backspace key sending + [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") } + #endregion Sendkey function + + # Force move the WPF form to the foreground + $Window.Add_Loaded({$Window.Activate()}) + $Form.ShowDialog() | Out-Null } #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,23 +11469,46 @@ function HEVC # Installing "HEVC Video Extensions from Device Manufacturer" if ([System.Version]$HEVCPackageName -gt [System.Version](Get-AppxPackage -Name Microsoft.HEVCVideoExtension).Version) { - Write-Information -MessageData "" -InformationAction Continue - # Extract the localized "Please wait..." string from shell32.dll - Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose + 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-Verbose -Message $Localization.HEVCDownloading -Verbose + Write-Information -MessageData "" -InformationAction Continue + # Extract the localized "Please wait..." string from shell32.dll + Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = $TempURL - OutFile = "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" - UseBasicParsing = $true - Verbose = $true + Write-Verbose -Message $Localization.HEVCDownloading -Verbose + + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = $TempURL + OutFile = "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Add-AppxPackage -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Verbose + Remove-Item -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Force } - Invoke-WebRequest @Parameters + 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 - Add-AppxPackage -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Verbose - Remove-Item -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Force + return + } } else { @@ -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 = @( diff --git a/src/Sophia_Script_for_Windows_10/Sophia.ps1 b/src/Sophia_Script_for_Windows_10/Sophia.ps1 index e81350084..256a731de 100644 --- a/src/Sophia_Script_for_Windows_10/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10/Sophia.ps1 @@ -1408,7 +1408,7 @@ UseStoreOpenWith -Hide #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Localizations/uk-UA/Sophia.psd1 index 012092baf..fb8b18f5b 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Localizations/uk-UA/Sophia.psd1 @@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 4da62585c..a906f0163 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -299,6 +299,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 @@ -513,52 +623,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_LTSC2019 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_LTSC2019 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether LGPO.exe exists in the bin folder @@ -617,40 +707,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10_LTSC_2019 - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10_LTSC_2019 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -697,137 +767,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -888,7 +827,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 @@ -3639,114 +3578,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } - } - catch [System.ComponentModel.Win32Exception] - { - Write-Warning -Message $Localization.NoInternetConnection - Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + } + 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 } @@ -3755,114 +3672,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } - } - catch [System.ComponentModel.Win32Exception] - { - Write-Warning -Message $Localization.NoInternetConnection - Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force + } + 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 } @@ -5154,10 +5049,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" @@ -8168,69 +8065,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $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 - } + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } - else - { - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters + Invoke-WebRequest @Parameters - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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 } @@ -8263,48 +8132,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 @@ -8315,7 +8149,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" @@ -8324,33 +8170,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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 @@ -8361,7 +8204,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" @@ -8370,17 +8225,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -10486,7 +10350,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") @@ -10568,6 +10432,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -10591,6 +10456,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -11131,8 +10997,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 } @@ -11222,8 +11088,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 } @@ -11344,7 +11210,7 @@ function MultipleInvokeContext <# .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 @@ -11375,6 +11241,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 @@ -11435,6 +11303,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 = @( diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 index fe1ad62cf..fe69c8051 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 @@ -1047,7 +1047,7 @@ MultipleInvokeContext -Enable #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Localizations/uk-UA/Sophia.psd1 index 4d8c34995..78727e090 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Localizations/uk-UA/Sophia.psd1 @@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 785f4af1d..7d66578cb 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -299,6 +299,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 @@ -513,52 +623,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_PowerShell_5_1 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_LTSC2021 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether LGPO.exe exists in the bin folder @@ -617,40 +707,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10_LTSC_2021 - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10_LTSC_2021 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -697,137 +767,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -888,7 +827,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 @@ -4015,114 +3954,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4131,114 +4048,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -5546,10 +5441,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" @@ -8799,69 +8696,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $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 + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } + Invoke-WebRequest @Parameters - 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 + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait - - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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 } @@ -8894,48 +8763,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 @@ -8946,7 +8780,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" @@ -8955,33 +8801,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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 @@ -8992,7 +8835,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" @@ -9001,17 +8856,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -9332,42 +9196,38 @@ function Install-WSL { try { - # Check the internet connection + # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json + # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" + UseBasicParsing = $true + Verbose = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") - { - return + $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + [PSCustomObject]@{ + "Distribution" = $_.FriendlyName + "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 - try - { - # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json - # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" - UseBasicParsing = $true - Verbose = $true - } - $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { - [PSCustomObject]@{ - "Distribution" = $_.FriendlyName - "Alias" = $_.Name - } - } + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - Add-Type -AssemblyName PresentationCore, PresentationFramework + return + } - #region Variables - $CommandTag = $null + Add-Type -AssemblyName PresentationCore, PresentationFramework - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" + #region Variables + $CommandTag = $null + + #region XAML Markup + # The section defines the design of the upcoming dialog box + [xml]$XAML = @" "@ - #endregion XAML Markup - - $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) - $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) - } + #endregion XAML Markup - $ButtonInstall.Content = $Localization.Install - #endregion Variables + $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) + $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) + } - #region Functions - function RadioButtonChecked - { - $Script:CommandTag = $_.OriginalSource.Tag - if (-not $ButtonInstall.IsEnabled) - { - $ButtonInstall.IsEnabled = $true - } - } + $ButtonInstall.Content = $Localization.Install + #endregion Variables - function ButtonInstallClicked - { - Write-Warning -Message $Script:CommandTag + #region Functions + function RadioButtonChecked + { + $Script:CommandTag = $_.OriginalSource.Tag + if (-not $ButtonInstall.IsEnabled) + { + $ButtonInstall.IsEnabled = $true + } + } - Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait + function ButtonInstallClicked + { + Write-Warning -Message $Script:CommandTag - $Form.Close() + Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait - # Receive updates for other Microsoft products when you update Windows - (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") + $Form.Close() - # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - } - #endregion + # Receive updates for other Microsoft products when you update Windows + (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") - foreach ($Distribution in $Distributions) - { - $Panel = New-Object -TypeName System.Windows.Controls.StackPanel - $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton - $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock - $Panel.Orientation = "Horizontal" - $RadioButton.GroupName = "WslDistribution" - $RadioButton.Tag = $Distribution.Alias - $RadioButton.Add_Checked({RadioButtonChecked}) - $TextBlock.Text = $Distribution.Distribution - $Panel.Children.Add($RadioButton) | Out-Null - $Panel.Children.Add($TextBlock) | Out-Null - $PanelContainer.Children.Add($Panel) | Out-Null - } + # Check for updates + Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + } + #endregion - $ButtonInstall.Add_Click({ButtonInstallClicked}) + foreach ($Distribution in $Distributions) + { + $Panel = New-Object -TypeName System.Windows.Controls.StackPanel + $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton + $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock + $Panel.Orientation = "Horizontal" + $RadioButton.GroupName = "WslDistribution" + $RadioButton.Tag = $Distribution.Alias + $RadioButton.Add_Checked({RadioButtonChecked}) + $TextBlock.Text = $Distribution.Distribution + $Panel.Children.Add($RadioButton) | Out-Null + $Panel.Children.Add($TextBlock) | Out-Null + $PanelContainer.Children.Add($Panel) | Out-Null + } - #region Sendkey function - # Emulate the Backspace key sending to prevent the console window to freeze - Start-Sleep -Milliseconds 500 + $ButtonInstall.Add_Click({ButtonInstallClicked}) - Add-Type -AssemblyName System.Windows.Forms + #region Sendkey function + # Emulate the Backspace key sending to prevent the console window to freeze + Start-Sleep -Milliseconds 500 - # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID - Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10 LTSC 2021")} | ForEach-Object -Process { - # Show window, if minimized - [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) + Add-Type -AssemblyName System.Windows.Forms - Start-Sleep -Seconds 1 + # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID + Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10 LTSC 2021")} | ForEach-Object -Process { + # Show window, if minimized + [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) - # Force move the console window to the foreground - [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) + Start-Sleep -Seconds 1 - Start-Sleep -Seconds 1 + # Force move the console window to the foreground + [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) - # Emulate the Backspace key sending - [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") - } - #endregion Sendkey function + Start-Sleep -Seconds 1 - # 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 + # Emulate the Backspace key sending + [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") } + #endregion Sendkey function + + # Force move the WPF form to the foreground + $Window.Add_Loaded({$Window.Activate()}) + $Form.ShowDialog() | Out-Null } #endregion WSL @@ -11617,7 +11465,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") @@ -11699,6 +11547,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -11722,6 +11571,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -11774,7 +11624,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] @@ -11783,7 +11633,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] @@ -12497,8 +12347,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 } @@ -12588,8 +12438,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 } @@ -12710,7 +12560,7 @@ function MultipleInvokeContext <# .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 @@ -12741,6 +12591,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 @@ -12801,6 +12653,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 = @( diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 index 936abacbf..436efe3c0 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 @@ -1212,7 +1212,7 @@ MultipleInvokeContext -Enable #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Localizations/uk-UA/Sophia.psd1 index 6bbba9167..ecef3b250 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Localizations/uk-UA/Sophia.psd1 @@ -12,7 +12,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1 index 014357895..a089f9f6f 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Manifest/Sophia.psd1 @@ -5,7 +5,7 @@ Author = 'Dmitry "farag" Nefedov' Copyright = '(c) 2014—2024 farag, Inestic & lowl1f3. All rights reserved' Description = 'Module for Windows fine-tuning and automating the routine tasks' - PowerShellVersion = '7.3' + PowerShellVersion = '7.4' ProcessorArchitecture = 'AMD64' FunctionsToExport = '*' diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 4e546b4b4..b2f41c128 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -300,6 +300,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 utf8NoBOM -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 utf8NoBOM -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 utf8NoBOM -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 @@ -551,52 +661,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_PowerShell_5_1 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_10_PowerShell_5_1 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether all necessary files exist in the bin folder @@ -650,40 +740,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_10 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -733,137 +803,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 utf8NoBOM -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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -924,7 +863,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 @@ -3714,7 +3653,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 } <# @@ -4744,114 +4683,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } + + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force + } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - } + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4860,114 +4777,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } + + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force + } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - } + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -5363,18 +5258,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 @@ -5413,12 +5296,14 @@ public static bool MarkFileDelete (string sourcefile) Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force } - 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 + + return } } @@ -6570,10 +6455,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" @@ -9945,7 +9832,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] @@ -9985,69 +9872,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $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 + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } + Invoke-WebRequest @Parameters - 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 + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait - - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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 } @@ -10080,48 +9939,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 @@ -10132,7 +9956,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" @@ -10141,33 +9977,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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 @@ -10178,7 +10011,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" @@ -10187,17 +10032,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -10518,42 +10372,38 @@ function Install-WSL { try { - # Check the internet connection + # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json + # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" + UseBasicParsing = $true + Verbose = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") - { - return + $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + [PSCustomObject]@{ + "Distribution" = $_.FriendlyName + "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 - try - { - # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json - # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" - UseBasicParsing = $true - Verbose = $true - } - $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { - [PSCustomObject]@{ - "Distribution" = $_.FriendlyName - "Alias" = $_.Name - } - } + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } - Add-Type -AssemblyName PresentationCore, PresentationFramework + Add-Type -AssemblyName PresentationCore, PresentationFramework - #region Variables - $CommandTag = $null + #region Variables + $CommandTag = $null - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" + #region XAML Markup + # The section defines the design of the upcoming dialog box + [xml]$XAML = @" "@ - #endregion XAML Markup - - $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) - $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) - } + #endregion XAML Markup - $ButtonInstall.Content = $Localization.Install - #endregion Variables + $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) + $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) + } - #region Functions - function RadioButtonChecked - { - $Script:CommandTag = $_.OriginalSource.Tag - if (-not $ButtonInstall.IsEnabled) - { - $ButtonInstall.IsEnabled = $true - } - } + $ButtonInstall.Content = $Localization.Install + #endregion Variables - function ButtonInstallClicked - { - Write-Warning -Message $Script:CommandTag + #region Functions + function RadioButtonChecked + { + $Script:CommandTag = $_.OriginalSource.Tag + if (-not $ButtonInstall.IsEnabled) + { + $ButtonInstall.IsEnabled = $true + } + } - Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait + function ButtonInstallClicked + { + Write-Warning -Message $Script:CommandTag - $Form.Close() + Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait - # Receive updates for other Microsoft products when you update Windows - (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") + $Form.Close() - # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - } - #endregion + # Receive updates for other Microsoft products when you update Windows + (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") - foreach ($Distribution in $Distributions) - { - $Panel = New-Object -TypeName System.Windows.Controls.StackPanel - $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton - $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock - $Panel.Orientation = "Horizontal" - $RadioButton.GroupName = "WslDistribution" - $RadioButton.Tag = $Distribution.Alias - $RadioButton.Add_Checked({RadioButtonChecked}) - $TextBlock.Text = $Distribution.Distribution - $Panel.Children.Add($RadioButton) | Out-Null - $Panel.Children.Add($TextBlock) | Out-Null - $PanelContainer.Children.Add($Panel) | Out-Null - } + # Check for updates + Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + } + #endregion - $ButtonInstall.Add_Click({ButtonInstallClicked}) + foreach ($Distribution in $Distributions) + { + $Panel = New-Object -TypeName System.Windows.Controls.StackPanel + $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton + $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock + $Panel.Orientation = "Horizontal" + $RadioButton.GroupName = "WslDistribution" + $RadioButton.Tag = $Distribution.Alias + $RadioButton.Add_Checked({RadioButtonChecked}) + $TextBlock.Text = $Distribution.Distribution + $Panel.Children.Add($RadioButton) | Out-Null + $Panel.Children.Add($TextBlock) | Out-Null + $PanelContainer.Children.Add($Panel) | Out-Null + } - #region Sendkey function - # Emulate the Backspace key sending to prevent the console window to freeze - Start-Sleep -Milliseconds 500 + $ButtonInstall.Add_Click({ButtonInstallClicked}) - Add-Type -AssemblyName System.Windows.Forms + #region Sendkey function + # Emulate the Backspace key sending to prevent the console window to freeze + Start-Sleep -Milliseconds 500 - # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID - Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10")} | ForEach-Object -Process { - # Show window, if minimized - [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) + Add-Type -AssemblyName System.Windows.Forms - Start-Sleep -Seconds 1 + # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID + Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10")} | ForEach-Object -Process { + # Show window, if minimized + [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) - # Force move the console window to the foreground - [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) + Start-Sleep -Seconds 1 - Start-Sleep -Seconds 1 + # Force move the console window to the foreground + [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) - # Emulate the Backspace key sending - [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") - } - #endregion Sendkey function + Start-Sleep -Seconds 1 - # 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 + # Emulate the Backspace key sending + [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") } + #endregion Sendkey function + + # Force move the WPF form to the foreground + $Window.Add_Loaded({$Window.Activate()}) + $Form.ShowDialog() | Out-Null } #endregion WSL @@ -11605,29 +11443,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" @@ -11670,23 +11485,46 @@ function HEVC # Installing "HEVC Video Extensions from Device Manufacturer" if ([System.Version]$HEVCPackageName -gt [System.Version](Get-AppxPackage -Name Microsoft.HEVCVideoExtension).Version) { - Write-Information -MessageData "" -InformationAction Continue - # Extract the localized "Please wait..." string from shell32.dll - Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose + 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-Verbose -Message $Localization.HEVCDownloading -Verbose + Write-Information -MessageData "" -InformationAction Continue + # Extract the localized "Please wait..." string from shell32.dll + Write-Verbose -Message ([WinAPI.GetStrings]::GetString(12612)) -Verbose - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = $TempURL - OutFile = "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" - UseBasicParsing = $true - Verbose = $true + Write-Verbose -Message $Localization.HEVCDownloading -Verbose + + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = $TempURL + OutFile = "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Add-AppxPackage -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Verbose + Remove-Item -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Force } - Invoke-WebRequest @Parameters + 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 - Add-AppxPackage -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Verbose - Remove-Item -Path "$DownloadsFolder\Microsoft.HEVCVideoExtension_8wekyb3d8bbwe.appx" -Force + return + } } else { @@ -11700,6 +11538,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" @@ -13729,7 +13569,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") @@ -13819,6 +13659,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -13842,6 +13683,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -13894,7 +13736,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] @@ -13903,7 +13745,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] @@ -14557,8 +14399,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 } @@ -14648,8 +14490,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 } @@ -14832,7 +14674,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 @@ -14863,6 +14705,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 @@ -14923,6 +14767,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 = @( diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 index 5c7d9a476..98481dfb7 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 @@ -1419,7 +1419,7 @@ UseStoreOpenWith -Hide #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы diff --git a/src/Sophia_Script_for_Windows_11/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_11/Localizations/uk-UA/Sophia.psd1 index cebb4bae4..a4a1a2ec3 100644 --- a/src/Sophia_Script_for_Windows_11/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_11/Localizations/uk-UA/Sophia.psd1 @@ -11,7 +11,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 285d1c751..c4567b082 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -287,6 +287,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 @@ -526,52 +636,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether LGPO.exe exists in the bin folder @@ -620,40 +710,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11 - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -703,137 +773,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -894,7 +833,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 @@ -4333,114 +4272,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4449,114 +4366,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4950,18 +4845,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 @@ -5000,12 +4883,14 @@ public static bool MarkFileDelete (string sourcefile) Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force } - 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 + + return } } @@ -6157,10 +6042,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" @@ -9597,69 +9484,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $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 + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } + Invoke-WebRequest @Parameters - 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 + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait - - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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 } @@ -9692,48 +9551,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 @@ -9744,7 +9568,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" @@ -9753,33 +9589,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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 @@ -9790,7 +9623,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" @@ -9799,17 +9644,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -10130,42 +9984,38 @@ function Install-WSL { try { - # Check the internet connection + # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json + # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" + UseBasicParsing = $true + Verbose = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") - { - return + $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + [PSCustomObject]@{ + "Distribution" = $_.FriendlyName + "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 - try - { - # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json - # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" - UseBasicParsing = $true - Verbose = $true - } - $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { - [PSCustomObject]@{ - "Distribution" = $_.FriendlyName - "Alias" = $_.Name - } - } + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - Add-Type -AssemblyName PresentationCore, PresentationFramework + return + } - #region Variables - $CommandTag = $null + Add-Type -AssemblyName PresentationCore, PresentationFramework - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" + #region Variables + $CommandTag = $null + + #region XAML Markup + # The section defines the design of the upcoming dialog box + [xml]$XAML = @" "@ - #endregion XAML Markup - - $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) - $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) - } + #endregion XAML Markup - $ButtonInstall.Content = $Localization.Install - #endregion Variables + $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) + $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) + } - #region Functions - function RadioButtonChecked - { - $Script:CommandTag = $_.OriginalSource.Tag - if (-not $ButtonInstall.IsEnabled) - { - $ButtonInstall.IsEnabled = $true - } - } + $ButtonInstall.Content = $Localization.Install + #endregion Variables - function ButtonInstallClicked - { - Write-Warning -Message $Script:CommandTag + #region Functions + function RadioButtonChecked + { + $Script:CommandTag = $_.OriginalSource.Tag + if (-not $ButtonInstall.IsEnabled) + { + $ButtonInstall.IsEnabled = $true + } + } - Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait + function ButtonInstallClicked + { + Write-Warning -Message $Script:CommandTag - $Form.Close() + Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait - # Receive updates for other Microsoft products when you update Windows - (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") + $Form.Close() - # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - } - #endregion + # Receive updates for other Microsoft products when you update Windows + (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") - foreach ($Distribution in $Distributions) - { - $Panel = New-Object -TypeName System.Windows.Controls.StackPanel - $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton - $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock - $Panel.Orientation = "Horizontal" - $RadioButton.GroupName = "WslDistribution" - $RadioButton.Tag = $Distribution.Alias - $RadioButton.Add_Checked({RadioButtonChecked}) - $TextBlock.Text = $Distribution.Distribution - $Panel.Children.Add($RadioButton) | Out-Null - $Panel.Children.Add($TextBlock) | Out-Null - $PanelContainer.Children.Add($Panel) | Out-Null - } + # Check for updates + Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + } + #endregion - $ButtonInstall.Add_Click({ButtonInstallClicked}) + foreach ($Distribution in $Distributions) + { + $Panel = New-Object -TypeName System.Windows.Controls.StackPanel + $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton + $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock + $Panel.Orientation = "Horizontal" + $RadioButton.GroupName = "WslDistribution" + $RadioButton.Tag = $Distribution.Alias + $RadioButton.Add_Checked({RadioButtonChecked}) + $TextBlock.Text = $Distribution.Distribution + $Panel.Children.Add($RadioButton) | Out-Null + $Panel.Children.Add($TextBlock) | Out-Null + $PanelContainer.Children.Add($Panel) | Out-Null + } - #region Sendkey function - # Emulate the Backspace key sending to prevent the console window to freeze - Start-Sleep -Milliseconds 500 + $ButtonInstall.Add_Click({ButtonInstallClicked}) - Add-Type -AssemblyName System.Windows.Forms + #region Sendkey function + # Emulate the Backspace key sending to prevent the console window to freeze + Start-Sleep -Milliseconds 500 - # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID - Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11")} | ForEach-Object -Process { - # Show window, if minimized - [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) + Add-Type -AssemblyName System.Windows.Forms - Start-Sleep -Seconds 1 + # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID + Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11")} | ForEach-Object -Process { + # Show window, if minimized + [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) - # Force move the console window to the foreground - [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) + Start-Sleep -Seconds 1 - Start-Sleep -Seconds 1 + # Force move the console window to the foreground + [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) - # Emulate the Backspace key sending - [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") - } - #endregion Sendkey function + Start-Sleep -Seconds 1 - # 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 + # Emulate the Backspace key sending + [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") } + #endregion Sendkey function + + # Force move the WPF form to the foreground + $Window.Add_Loaded({$Window.Activate()}) + $Form.ShowDialog() | Out-Null } #endregion WSL @@ -12874,7 +12712,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") @@ -12964,6 +12802,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -12987,6 +12826,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -13038,7 +12878,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS) })] [string] @@ -13046,7 +12886,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS) })] [string] @@ -13888,7 +13728,7 @@ function OpenWindowsTerminalAdminContext <# .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 @@ -13919,6 +13759,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 @@ -13979,6 +13821,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 = @( diff --git a/src/Sophia_Script_for_Windows_11/Sophia.ps1 b/src/Sophia_Script_for_Windows_11/Sophia.ps1 index f235bbb86..f8b0b226e 100644 --- a/src/Sophia_Script_for_Windows_11/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11/Sophia.ps1 @@ -1338,7 +1338,7 @@ OpenWindowsTerminalAdminContext -Enable #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы diff --git a/src/Sophia_Script_for_Windows_11_LTSC_2024/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_11_LTSC_2024/Localizations/uk-UA/Sophia.psd1 index b155ee1f0..85fce360c 100644 --- a/src/Sophia_Script_for_Windows_11_LTSC_2024/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_11_LTSC_2024/Localizations/uk-UA/Sophia.psd1 @@ -11,7 +11,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. 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 972d67b15..aa9a16c29 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 @@ -285,6 +285,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 @@ -511,52 +621,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_LTSC2024 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_LTSC2024 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether LGPO.exe exists in the bin folder @@ -616,40 +706,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_LTSC2024 - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11_LTSC_2024 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -696,137 +766,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -887,7 +826,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 @@ -4120,114 +4059,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4236,114 +4153,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -5703,10 +5598,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" @@ -9066,69 +8963,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } - 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 = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait + Invoke-WebRequest @Parameters - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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 } @@ -9161,48 +9030,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 @@ -9213,7 +9047,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" @@ -9222,33 +9068,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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 @@ -9259,7 +9102,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" @@ -9268,17 +9123,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -9599,42 +9463,38 @@ function Install-WSL { try { - # Check the internet connection + # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json + # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" + UseBasicParsing = $true + Verbose = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") - { - return + $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + [PSCustomObject]@{ + "Distribution" = $_.FriendlyName + "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 - try - { - # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json - # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" - UseBasicParsing = $true - Verbose = $true - } - $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { - [PSCustomObject]@{ - "Distribution" = $_.FriendlyName - "Alias" = $_.Name - } - } + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - Add-Type -AssemblyName PresentationCore, PresentationFramework + return + } - #region Variables - $CommandTag = $null + Add-Type -AssemblyName PresentationCore, PresentationFramework - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" + #region Variables + $CommandTag = $null + + #region XAML Markup + # The section defines the design of the upcoming dialog box + [xml]$XAML = @" "@ - #endregion XAML Markup - - $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) - $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) - } + #endregion XAML Markup - $ButtonInstall.Content = $Localization.Install - #endregion Variables + $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) + $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) + } - #region Functions - function RadioButtonChecked - { - $Script:CommandTag = $_.OriginalSource.Tag - if (-not $ButtonInstall.IsEnabled) - { - $ButtonInstall.IsEnabled = $true - } - } + $ButtonInstall.Content = $Localization.Install + #endregion Variables - function ButtonInstallClicked - { - Write-Warning -Message $Script:CommandTag + #region Functions + function RadioButtonChecked + { + $Script:CommandTag = $_.OriginalSource.Tag + if (-not $ButtonInstall.IsEnabled) + { + $ButtonInstall.IsEnabled = $true + } + } - Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait + function ButtonInstallClicked + { + Write-Warning -Message $Script:CommandTag - $Form.Close() + Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait - # Receive updates for other Microsoft products when you update Windows - (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") + $Form.Close() - # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - } - #endregion + # Receive updates for other Microsoft products when you update Windows + (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") - foreach ($Distribution in $Distributions) - { - $Panel = New-Object -TypeName System.Windows.Controls.StackPanel - $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton - $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock - $Panel.Orientation = "Horizontal" - $RadioButton.GroupName = "WslDistribution" - $RadioButton.Tag = $Distribution.Alias - $RadioButton.Add_Checked({RadioButtonChecked}) - $TextBlock.Text = $Distribution.Distribution - $Panel.Children.Add($RadioButton) | Out-Null - $Panel.Children.Add($TextBlock) | Out-Null - $PanelContainer.Children.Add($Panel) | Out-Null - } + # Check for updates + Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + } + #endregion - $ButtonInstall.Add_Click({ButtonInstallClicked}) + foreach ($Distribution in $Distributions) + { + $Panel = New-Object -TypeName System.Windows.Controls.StackPanel + $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton + $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock + $Panel.Orientation = "Horizontal" + $RadioButton.GroupName = "WslDistribution" + $RadioButton.Tag = $Distribution.Alias + $RadioButton.Add_Checked({RadioButtonChecked}) + $TextBlock.Text = $Distribution.Distribution + $Panel.Children.Add($RadioButton) | Out-Null + $Panel.Children.Add($TextBlock) | Out-Null + $PanelContainer.Children.Add($Panel) | Out-Null + } - #region Sendkey function - # Emulate the Backspace key sending to prevent the console window to freeze - Start-Sleep -Milliseconds 500 + $ButtonInstall.Add_Click({ButtonInstallClicked}) - Add-Type -AssemblyName System.Windows.Forms + #region Sendkey function + # Emulate the Backspace key sending to prevent the console window to freeze + Start-Sleep -Milliseconds 500 - # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID - Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11 LTSC 2024")} | ForEach-Object -Process { - # Show window, if minimized - [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) + Add-Type -AssemblyName System.Windows.Forms - Start-Sleep -Seconds 1 + # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID + Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11 LTSC 2024")} | ForEach-Object -Process { + # Show window, if minimized + [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) - # Force move the console window to the foreground - [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) + Start-Sleep -Seconds 1 - Start-Sleep -Seconds 1 + # Force move the console window to the foreground + [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) - # Emulate the Backspace key sending - [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") - } - #endregion Sendkey function + Start-Sleep -Seconds 1 - # 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 + # Emulate the Backspace key sending + [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") } + #endregion Sendkey function + + # Force move the WPF form to the foreground + $Window.Add_Loaded({$Window.Activate()}) + $Form.ShowDialog() | Out-Null } #endregion WSL @@ -9907,10 +9755,10 @@ function UninstallUWPApps # Xbox Speech To Text Overlay "Microsoft.XboxSpeechToTextOverlay", - # Xbox Game Bar + # Game Bar "Microsoft.XboxGamingOverlay", - # Xbox Game Bar Plugin + # Game Bar Plugin "Microsoft.XboxGameOverlay" ) @@ -9923,6 +9771,10 @@ function UninstallUWPApps "AppUp.IntelGraphicsControlPanel", "AppUp.IntelGraphicsExperience", + # ELAN Touchpad + "ELANMicroelectronicsCorpo.ELANTouchpadforThinkpad", + "ELANMicroelectronicsCorpo.ELANTrackPointforThinkpa", + # Microsoft Application Compatibility Enhancements "Microsoft.ApplicationCompatibilityEnhancements", @@ -9983,7 +9835,11 @@ function UninstallUWPApps "NVIDIACorp.NVIDIAControlPanel", # Realtek Audio Console - "RealtekSemiconductorCorp.RealtekAudioControl" + "RealtekSemiconductorCorp.RealtekAudioControl", + + # Synaptics + "SynapticsIncorporated.SynapticsControlPanel", + "SynapticsIncorporated.24916F58D6E7" ) #region Variables @@ -10208,7 +10064,7 @@ function UninstallUWPApps $Window.Close() | Out-Null - # If Xbox Game Bar is selected to uninstall stop its processes + # If Game Bar is selected to uninstall stop its processes if ($PackagesToRemove -match "Microsoft.XboxGamingOverlay") { Get-Process -Name GameBar, GameBarFTServer -ErrorAction Ignore | Stop-Process -Force @@ -12094,7 +11950,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") @@ -12176,6 +12032,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -12199,6 +12056,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -12250,7 +12108,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS) })] [string] @@ -12258,7 +12116,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS) })] [string] @@ -12740,7 +12598,7 @@ function MultipleInvokeContext <# .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 @@ -12771,6 +12629,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 @@ -12831,6 +12691,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 = @( diff --git a/src/Sophia_Script_for_Windows_11_LTSC_2024/Sophia.ps1 b/src/Sophia_Script_for_Windows_11_LTSC_2024/Sophia.ps1 index c07bee6a6..05ce61144 100644 --- a/src/Sophia_Script_for_Windows_11_LTSC_2024/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11_LTSC_2024/Sophia.ps1 @@ -1225,7 +1225,7 @@ MultipleInvokeContext -Enable #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Localizations/uk-UA/Sophia.psd1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Localizations/uk-UA/Sophia.psd1 index cebb4bae4..a4a1a2ec3 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Localizations/uk-UA/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Localizations/uk-UA/Sophia.psd1 @@ -11,7 +11,7 @@ TweakerWarning = Стабільність вашої Bin = У папці bin відсутні файли. Будь ласка, повторно завантажте архів. RebootPending = Комп'ютер очікує на перезавантаження. UnsupportedRelease = Виявлено нову версію. -KeyboardArrows = Для вибору відповіді на клавіатурі стрілки {0} і {1} +KeyboardArrows = Для вибору відповіді використовуйте на клавіатурі стрілки {0} і {1} CustomizationWarning = Ви налаштували всі функції в пресет-файлі {0} перед запуском Sophia Script? WindowsComponentBroken = {0} пошкоджено або видалено з ОС. UpdateDefender = Визначення Microsoft Defender застаріли. Запустіть Windows Update і повторіть спробу. diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1 index 2a38b8774..d549b700a 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Manifest/Sophia.psd1 @@ -5,7 +5,7 @@ Author = 'Dmitry "farag" Nefedov' Copyright = '(c) 2014—2024 farag, Inestic & lowl1f3. All rights reserved' Description = 'Module for Windows fine-tuning and automating the routine tasks' - PowerShellVersion = '7.3' + PowerShellVersion = '7.4' ProcessorArchitecture = 'AMD64' FunctionsToExport = '*' 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 629af5122..3792f7766 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 @@ -286,6 +286,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 utf8NoBOM -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 utf8NoBOM -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 utf8NoBOM -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 @@ -525,52 +635,32 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json $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 + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Verbose = $true + UseBasicParsing = $true } + $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1 + $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - try + if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) { - # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestRelease = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1 - $CurrentRelease = (Get-Module -Name Sophia).Version.ToString() - - if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.UnsupportedRelease - Write-Information -MessageData "" -InformationAction Continue + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.UnsupportedRelease + Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose + Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose + Write-Verbose -Message "https://t.me/sophia_chat" -Verbose + Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - exit - } - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + exit } } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue } # Check whether all necessary files exist in the bin folder @@ -624,40 +714,20 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether the current module version is the latest one try { - # Check the internet connection + # https://github.com/farag2/Sophia-Script-for-Windows/blob/master/supported_windows_builds.json $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 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" - Verbose = $true - UseBasicParsing = $true - } - $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11 - } - catch [System.Net.WebException] - { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/supported_windows_builds.json" + Verbose = $true + UseBasicParsing = $true } + $LatestSupportedBuild = (Invoke-RestMethod @Parameters).Windows_11 } - catch [System.ComponentModel.Win32Exception] + catch [System.Net.WebException] { $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 @@ -707,137 +777,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); 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 utf8NoBOM -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 - } - } - 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 - } - # 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\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -898,7 +837,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 @@ -4337,114 +4276,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" - OutFile = "$DownloadsFolder\dark.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", - "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\dark.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/dark.zip" + OutFile = "$DownloadsFolder\dark.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_dark_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_dark_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\dark.zip`" -C `"$env:SystemRoot\Cursors\W11_dark_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursors Dark Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_dark_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\busy.ani", + "%SystemRoot%\Cursors\W11_dark_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_dark_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursors Dark Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\dark.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4453,114 +4370,92 @@ function Cursors { try { - # Check the internet connection + # Check whether https://github.com is alive $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://github.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") + if (-not (Invoke-WebRequest @Parameters).StatusDescription) { 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 - } - - $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" - OutFile = "$DownloadsFolder\light.zip" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) - { - New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force - } - - # Extract archive - Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" - - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force - New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force - - if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) - { - New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force - } - [string[]]$Schemes = ( - "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", - "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, - "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", - "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" - ) -join "," - New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force - - Start-Sleep -Seconds 1 - - Remove-Item -Path "$DownloadsFolder\light.zip" -Force + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/raw/master/Misc/light.zip" + OutFile = "$DownloadsFolder\light.zip" + UseBasicParsing = $true + Verbose = $true } - catch [System.Net.WebException] + Invoke-WebRequest @Parameters + + if (-not (Test-Path -Path "$env:SystemRoot\Cursors\W11_light_v2.2")) { - Write-Warning -Message ($Localization.NoResponse -f "https://github.com") - Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue + New-Item -Path "$env:SystemRoot\Cursors\W11_light_v2.2" -ItemType Directory -Force + } - Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + # Extract archive + Start-Process -FilePath "$env:SystemRoot\System32\tar.exe" -ArgumentList "-xf `"$DownloadsFolder\light.zip`" -C `"$env:SystemRoot\Cursors\W11_light_v2.2`" -v" + + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(default)" -PropertyType String -Value "W11 Cursor Light Free v2.2 by Jepri Creations" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name AppStarting -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\working.ani" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Arrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name ContactVisualization -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Crosshair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name CursorBaseSize -PropertyType DWord -Value 32 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name GestureVisualization -PropertyType DWord -Value 31 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Hand -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\link.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Help -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\help.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name IBeam -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name No -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name NWPen -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Person -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\person.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Pin -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name precisionhair -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeAll -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\move.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNESW -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNS -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeNWSE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name SizeWE -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name UpArrow -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur" -Force + New-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name Wait -PropertyType ExpandString -Value "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani" -Force + + if (-not (Test-Path -Path "HKCU:\Control Panel\Cursors\Schemes")) + { + New-Item -Path "HKCU:\Control Panel\Cursors\Schemes" -Force } + [string[]]$Schemes = ( + "%SystemRoot%\Cursors\W11_light_v2.2\pointer.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\help.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\working.ani", + "%SystemRoot%\Cursors\W11_light_v2.2\busy.ani",, + "%SystemRoot%\Cursors\W11_light_v2.2\precision.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\beam.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\handwriting.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\unavailable.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\vert.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\horz.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn1.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\dgn2.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\move.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\alternate.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\link.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\person.cur", + "%SystemRoot%\Cursors\W11_light_v2.2\pin.cur" + ) -join "," + New-ItemProperty -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "W11 Cursor Light Free v2.2 by Jepri Creations" -PropertyType String -Value $Schemes -Force + + Start-Sleep -Seconds 1 + + Remove-Item -Path "$DownloadsFolder\light.zip" -Force } - 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://github.com") + Write-Error -Message ($Localization.NoResponse -f "https://github.com") -ErrorAction SilentlyContinue Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } @@ -4956,18 +4851,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 @@ -5006,12 +4889,14 @@ public static bool MarkFileDelete (string sourcefile) Remove-Item -Path "$DownloadsFolder\OneDriveSetup.exe" -Force } - 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 + + return } } @@ -6163,10 +6048,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" @@ -9603,69 +9490,41 @@ function InstallVCRedist { try { - # Check the internet connection + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $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 + Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" + OutFile = "$DownloadsFolder\VC_redist.x86.exe" + UseBasicParsing = $true + Verbose = $true } + Invoke-WebRequest @Parameters - 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 + Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - # 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 = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait - - $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait - - # 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 - $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log" - ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore - } + $Parameters = @{ + Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" + OutFile = "$DownloadsFolder\VC_redist.x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + 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 } @@ -9698,48 +9557,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 @@ -9750,7 +9574,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" @@ -9759,33 +9595,30 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + 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 @@ -9796,7 +9629,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" @@ -9805,17 +9650,26 @@ 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 - Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - # 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 - $Paths = @( - "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", - "$env:TEMP\Microsoft_.NET_Runtime*.log" - ) - Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + return } + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # 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 + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } } @@ -10136,42 +9990,38 @@ function Install-WSL { try { - # Check the internet connection + # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json + # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output $Parameters = @{ - Name = "dns.msftncsi.com" - Server = "1.1.1.1" - DnsOnly = $true - ErrorAction = "Stop" + Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" + UseBasicParsing = $true + Verbose = $true } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") - { - return + $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + [PSCustomObject]@{ + "Distribution" = $_.FriendlyName + "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 - try - { - # https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json - # wsl --list --online relies on Internet connection too, so it's much convenient to parse DistributionInfo.json, rather than parse a cmd output - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json" - UseBasicParsing = $true - Verbose = $true - } - $Distributions = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { - [PSCustomObject]@{ - "Distribution" = $_.FriendlyName - "Alias" = $_.Name - } - } + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue - Add-Type -AssemblyName PresentationCore, PresentationFramework + return + } - #region Variables - $CommandTag = $null + Add-Type -AssemblyName PresentationCore, PresentationFramework - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" + #region Variables + $CommandTag = $null + + #region XAML Markup + # The section defines the design of the upcoming dialog box + [xml]$XAML = @" "@ - #endregion XAML Markup - - $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) - $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { - Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) - } + #endregion XAML Markup - $ButtonInstall.Content = $Localization.Install - #endregion Variables + $Form = [Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $XAML)) + $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { + Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name) + } - #region Functions - function RadioButtonChecked - { - $Script:CommandTag = $_.OriginalSource.Tag - if (-not $ButtonInstall.IsEnabled) - { - $ButtonInstall.IsEnabled = $true - } - } + $ButtonInstall.Content = $Localization.Install + #endregion Variables - function ButtonInstallClicked - { - Write-Warning -Message $Script:CommandTag + #region Functions + function RadioButtonChecked + { + $Script:CommandTag = $_.OriginalSource.Tag + if (-not $ButtonInstall.IsEnabled) + { + $ButtonInstall.IsEnabled = $true + } + } - Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait + function ButtonInstallClicked + { + Write-Warning -Message $Script:CommandTag - $Form.Close() + Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait - # Receive updates for other Microsoft products when you update Windows - (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") + $Form.Close() - # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan - } - #endregion + # Receive updates for other Microsoft products when you update Windows + (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") - foreach ($Distribution in $Distributions) - { - $Panel = New-Object -TypeName System.Windows.Controls.StackPanel - $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton - $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock - $Panel.Orientation = "Horizontal" - $RadioButton.GroupName = "WslDistribution" - $RadioButton.Tag = $Distribution.Alias - $RadioButton.Add_Checked({RadioButtonChecked}) - $TextBlock.Text = $Distribution.Distribution - $Panel.Children.Add($RadioButton) | Out-Null - $Panel.Children.Add($TextBlock) | Out-Null - $PanelContainer.Children.Add($Panel) | Out-Null - } + # Check for updates + Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + } + #endregion - $ButtonInstall.Add_Click({ButtonInstallClicked}) + foreach ($Distribution in $Distributions) + { + $Panel = New-Object -TypeName System.Windows.Controls.StackPanel + $RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton + $TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock + $Panel.Orientation = "Horizontal" + $RadioButton.GroupName = "WslDistribution" + $RadioButton.Tag = $Distribution.Alias + $RadioButton.Add_Checked({RadioButtonChecked}) + $TextBlock.Text = $Distribution.Distribution + $Panel.Children.Add($RadioButton) | Out-Null + $Panel.Children.Add($TextBlock) | Out-Null + $PanelContainer.Children.Add($Panel) | Out-Null + } - #region Sendkey function - # Emulate the Backspace key sending to prevent the console window to freeze - Start-Sleep -Milliseconds 500 + $ButtonInstall.Add_Click({ButtonInstallClicked}) - Add-Type -AssemblyName System.Windows.Forms + #region Sendkey function + # Emulate the Backspace key sending to prevent the console window to freeze + Start-Sleep -Milliseconds 500 - # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID - Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11")} | ForEach-Object -Process { - # Show window, if minimized - [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) + Add-Type -AssemblyName System.Windows.Forms - Start-Sleep -Seconds 1 + # We cannot use Get-Process -Id $PID as script might be invoked via Terminal with different $PID + Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11")} | ForEach-Object -Process { + # Show window, if minimized + [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) - # Force move the console window to the foreground - [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) + Start-Sleep -Seconds 1 - Start-Sleep -Seconds 1 + # Force move the console window to the foreground + [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) - # Emulate the Backspace key sending - [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") - } - #endregion Sendkey function + Start-Sleep -Seconds 1 - # 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 + # Emulate the Backspace key sending + [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}") } + #endregion Sendkey function + + # Force move the WPF form to the foreground + $Window.Add_Loaded({$Window.Activate()}) + $Form.ShowDialog() | Out-Null } #endregion WSL @@ -10454,10 +10292,10 @@ function UninstallUWPApps # Xbox Speech To Text Overlay "Microsoft.XboxSpeechToTextOverlay", - # Xbox Game Bar + # Game Bar "Microsoft.XboxGamingOverlay", - # Xbox Game Bar Plugin + # Game Bar Plugin "Microsoft.XboxGameOverlay" ) @@ -10763,7 +10601,7 @@ function UninstallUWPApps $Window.Close() | Out-Null - # If Xbox Game Bar is selected to uninstall stop its processes + # If Game Bar is selected to uninstall stop its processes if ($PackagesToRemove -match "Microsoft.XboxGamingOverlay") { Get-Process -Name GameBar, GameBarFTServer -ErrorAction Ignore | Stop-Process -Force @@ -11018,13 +10856,13 @@ function TeamsAutostart #region Gaming <# .SYNOPSIS - Xbox Game Bar + Game Bar .PARAMETER Disable - Disable Xbox Game Bar + Disable Game Bar .PARAMETER Enable - Enable Xbox Game Bar + Enable Game Bar .EXAMPLE XboxGameBar -Disable @@ -11033,7 +10871,7 @@ function TeamsAutostart XboxGameBar -Enable .NOTES - To prevent popping up the "You'll need a new app to open this ms-gamingoverlay" warning, you need to disable the Xbox Game Bar app, even if you uninstalled it before + To prevent popping up the "You'll need a new app to open this ms-gamingoverlay" warning, you need to disable the Game Bar app, even if you uninstalled it before .NOTES Current user @@ -11074,13 +10912,13 @@ function XboxGameBar <# .SYNOPSIS - Xbox Game Bar tips + Game Bar tips .PARAMETER Disable - Disable Xbox Game Bar tips + Disable Game Bar tips .PARAMETER Enable - Enable Xbox Game Bar tips + Enable Game Bar tips .EXAMPLE XboxGameTips -Disable @@ -12890,7 +12728,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") @@ -12980,6 +12818,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -13003,6 +12842,7 @@ function WindowsSandbox catch [System.Exception] { Write-Error -Message $Localization.EnableHardwareVT -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } } } @@ -13054,7 +12894,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS) })] [string] @@ -13062,7 +12902,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and Check whether $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS) })] [string] @@ -13463,7 +13303,7 @@ function EditWithClipchampContext .NOTES Current user #> -function EditWithPhotosContext +function EditWithPhotosContext { param ( @@ -13904,7 +13744,7 @@ function OpenWindowsTerminalAdminContext <# .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 @@ -13935,6 +13775,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 @@ -13995,6 +13837,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 = @( diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 index 8df37ea64..c7be8662d 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 @@ -1349,7 +1349,7 @@ OpenWindowsTerminalAdminContext -Enable #region Update Policies <# 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 Отобразить все политики реестра (даже созданные вручную) в оснастке Редактора локальной групповой политики (gpedit.msc) Это может занять до 30 минут в зависимости от количества политик, созданных в реестре, и мощности вашей системы