From 19aa9741fb5f2026eb88f66a7ed054f86b20178e Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Mon, 27 Mar 2023 22:56:02 +0300 Subject: [PATCH] Added new checks Improved Checks Added new checks fixed typo --- .../Module/Sophia.psm1 | 99 ++++++++++++++--- .../Module/Sophia.psm1 | 6 ++ .../Module/Sophia.psm1 | 6 ++ .../Module/Sophia.psm1 | 102 ++++++++++++++---- .../Module/Sophia.psm1 | 99 ++++++++++++++--- .../Module/Sophia.psm1 | 102 ++++++++++++++---- 6 files changed, 348 insertions(+), 66 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index d8e1308f..7adb5eb6 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -540,6 +540,90 @@ public static string GetString(uint strId) Add-Type @Signature } + # Enable back the SysMain service if it was disabled by harmful tweakers + if ((Get-Service -Name SysMain).Status -eq "Stopped") + { + Get-Service -Name SysMain | Set-Service -StartupType Automatic + Get-Service -Name SysMain | Start-Service + + Start-Process -FilePath "https://www.outsidethebox.ms/19318/" + } + + # Automatically manage paging file size for all drives + if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile) + { + Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true} + } + + # Check if Microsoft Edge as being a system component was removed by harmful tweakers + if (Test-Path -Path "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe") + { + return + } + else + { + Write-Information -MessageData "" -InformationAction Continue + # Extract the localized "Please wait..." string from shell32.dll + Write-Verbose -Message ([WinAPI.GetStr]::GetString(12612)) -Verbose + + try + { + # Check the internet connection + $Parameters = @{ + Uri = "https://www.google.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true + } + if (-not (Invoke-WebRequest @Parameters).StatusDescription) + { + return + } + + try + { + # Download Microsoft Edge Stable x64 + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&source=EdgeStablePage&Channel=Stable&language=$((Get-WinSystemLocale).TwoLetterISOLanguageName)" + OutFile = "$DownloadsFolder\MicrosoftEdgeSetup.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-Webrequest @Parameters + + # Install Microsoft Edge Stable x64 + Start-Process -FilePath "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Wait + + Get-Process -Name msedge | Stop-Process -Force -ErrorAction Ignore + Start-Sleep -Seconds 5 + + & "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe" --no-first-run --noerrdialogs --no-default-browser-check --start-maximized + + Remove-Item -Path "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Force + + Start-Process -FilePath "https://t.me/sophia_chat" + Start-Process -FilePath "https://discord.gg/sSryhaEv79" + } + catch [System.Net.WebException] + { + Write-Warning -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") + Write-Error -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") -ErrorAction SilentlyContinue + } + } + catch [System.Net.WebException] + { + Write-Warning -Message $Localization.NoInternetConnection + Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue + } + } + + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word + Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + + # Save all opened folders in order to restore them after File Explorer restart + $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() + # Display a warning message about whether a user has customized the preset file if ($Warning) { @@ -576,21 +660,6 @@ public static string GetString(uint strId) } } } - - # Enable back the SysMain service if it was disabled by harmful tweakers - if ((Get-Service -Name SysMain).Status -eq "Stopped") - { - Get-Service -Name SysMain | Set-Service -StartupType Automatic - Get-Service -Name SysMain | Start-Service - - Start-Process -FilePath "https://www.outsidethebox.ms/19318/" - } - - # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word - Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore - - # Save all opened folders in order to restore them after File Explorer restart - $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() } #endregion Checks 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 3ed9dcc3..67b78ab9 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 @@ -546,6 +546,12 @@ public static string GetString(uint strId) Start-Process -FilePath "https://www.outsidethebox.ms/19318/" } + # Automatically manage paging file size for all drives + if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile) + { + Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true} + } + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore 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 32db3512..fd62c31c 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 @@ -546,6 +546,12 @@ public static string GetString(uint strId) Start-Process -FilePath "https://www.outsidethebox.ms/19318/" } + # Automatically manage paging file size for all drives + if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile) + { + Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true} + } + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore 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 5d3e65eb..eba51bfd 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 @@ -546,6 +546,90 @@ public static string GetString(uint strId) Add-Type @Signature } + # Enable back the SysMain service if it was disabled by harmful tweakers + if ((Get-Service -Name SysMain).Status -eq "Stopped") + { + Get-Service -Name SysMain | Set-Service -StartupType Automatic + Get-Service -Name SysMain | Start-Service + + Start-Process -FilePath "https://www.outsidethebox.ms/19318/" + } + + # Automatically manage paging file size for all drives + if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile) + { + Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true} + } + + # Check if Microsoft Edge as being a system component was removed by harmful tweakers + if (Test-Path -Path "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe") + { + return + } + else + { + Write-Information -MessageData "" -InformationAction Continue + # Extract the localized "Please wait..." string from shell32.dll + Write-Verbose -Message ([WinAPI.GetStr]::GetString(12612)) -Verbose + + try + { + # Check the internet connection + $Parameters = @{ + Uri = "https://www.google.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true + } + if (-not (Invoke-WebRequest @Parameters).StatusDescription) + { + return + } + + try + { + # Download Microsoft Edge Stable x64 + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&source=EdgeStablePage&Channel=Stable&language=$((Get-WinSystemLocale).TwoLetterISOLanguageName)" + OutFile = "$DownloadsFolder\MicrosoftEdgeSetup.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-Webrequest @Parameters + + # Install Microsoft Edge Stable x64 + Start-Process -FilePath "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Wait + + Get-Process -Name msedge | Stop-Process -Force -ErrorAction Ignore + Start-Sleep -Seconds 5 + + & "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe" --no-first-run --noerrdialogs --no-default-browser-check --start-maximized + + Remove-Item -Path "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Force + + Start-Process -FilePath "https://t.me/sophia_chat" + Start-Process -FilePath "https://discord.gg/sSryhaEv79" + } + catch [System.Net.WebException] + { + Write-Warning -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") + Write-Error -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") -ErrorAction SilentlyContinue + } + } + catch [System.Net.WebException] + { + Write-Warning -Message $Localization.NoInternetConnection + Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue + } + } + + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word + Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + + # Save all opened folders in order to restore them after File Explorer restart + $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() + # Display a warning message about whether a user has customized the preset file if ($Warning) { @@ -582,24 +666,6 @@ public static string GetString(uint strId) } } } - - # Enable back the SysMain service if it was disabled by harmful tweakers - if ((Get-Service -Name SysMain).Status -eq "Stopped") - { - Get-Service -Name SysMain | Set-Service -StartupType Automatic - Get-Service -Name SysMain | Start-Service - - Start-Process -FilePath "https://www.outsidethebox.ms/19318/" - } - - # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word - Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore - - # Import PowerShell 5.1 modules - Import-Module -Name Microsoft.PowerShell.Management, PackageManagement, Appx -UseWindowsPowerShell - - # Save all opened folders in order to restore them after File Explorer restart - $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() } #endregion Checks diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index ab070503..8101d403 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -594,6 +594,90 @@ public static string GetString(uint strId) Add-Type @Signature } + # Enable back the SysMain service if it was disabled by harmful tweakers + if ((Get-Service -Name SysMain).Status -eq "Stopped") + { + Get-Service -Name SysMain | Set-Service -StartupType Automatic + Get-Service -Name SysMain | Start-Service + + Start-Process -FilePath "https://www.outsidethebox.ms/19318/" + } + + # Automatically manage paging file size for all drives + if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile) + { + Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true} + } + + # Check if Microsoft Edge as being a system component was removed by harmful tweakers + if (Test-Path -Path "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe") + { + return + } + else + { + Write-Information -MessageData "" -InformationAction Continue + # Extract the localized "Please wait..." string from shell32.dll + Write-Verbose -Message ([WinAPI.GetStr]::GetString(12612)) -Verbose + + try + { + # Check the internet connection + $Parameters = @{ + Uri = "https://www.google.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true + } + if (-not (Invoke-WebRequest @Parameters).StatusDescription) + { + return + } + + try + { + # Download Microsoft Edge Stable x64 + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&source=EdgeStablePage&Channel=Stable&language=$((Get-WinSystemLocale).TwoLetterISOLanguageName)" + OutFile = "$DownloadsFolder\MicrosoftEdgeSetup.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-Webrequest @Parameters + + # Install Microsoft Edge Stable x64 + Start-Process -FilePath "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Wait + + Get-Process -Name msedge | Stop-Process -Force -ErrorAction Ignore + Start-Sleep -Seconds 5 + + & "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe" --no-first-run --noerrdialogs --no-default-browser-check --start-maximized + + Remove-Item -Path "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Force + + Start-Process -FilePath "https://t.me/sophia_chat" + Start-Process -FilePath "https://discord.gg/sSryhaEv79" + } + catch [System.Net.WebException] + { + Write-Warning -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") + Write-Error -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") -ErrorAction SilentlyContinue + } + } + catch [System.Net.WebException] + { + Write-Warning -Message $Localization.NoInternetConnection + Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue + } + } + + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word + Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + + # Save all opened folders in order to restore them after File Explorer restart + $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() + # Display a warning message about whether a user has customized the preset file if ($Warning) { @@ -630,21 +714,6 @@ public static string GetString(uint strId) } } } - - # Enable back the SysMain service if it was disabled by harmful tweakers - if ((Get-Service -Name SysMain).Status -eq "Stopped") - { - Get-Service -Name SysMain | Set-Service -StartupType Automatic - Get-Service -Name SysMain | Start-Service - - Start-Process -FilePath "https://www.outsidethebox.ms/19318/" - } - - # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word - Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore - - # Save all opened folders in order to restore them after File Explorer restart - $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() } #endregion Checks 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 15c31b78..a4cbf8ab 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 @@ -599,6 +599,90 @@ public static string GetString(uint strId) Add-Type @Signature } + # Enable back the SysMain service if it was disabled by harmful tweakers + if ((Get-Service -Name SysMain).Status -eq "Stopped") + { + Get-Service -Name SysMain | Set-Service -StartupType Automatic + Get-Service -Name SysMain | Start-Service + + Start-Process -FilePath "https://www.outsidethebox.ms/19318/" + } + + # Automatically manage paging file size for all drives + if (-not (Get-CimInstance -ClassName CIM_ComputerSystem).AutomaticManagedPageFile) + { + Get-CimInstance -ClassName CIM_ComputerSystem | Set-CimInstance -Property @{AutomaticManagedPageFile = $true} + } + + # Check if Microsoft Edge as being a system component was removed by harmful tweakers + if (Test-Path -Path "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe") + { + return + } + else + { + Write-Information -MessageData "" -InformationAction Continue + # Extract the localized "Please wait..." string from shell32.dll + Write-Verbose -Message ([WinAPI.GetStr]::GetString(12612)) -Verbose + + try + { + # Check the internet connection + $Parameters = @{ + Uri = "https://www.google.com" + Method = "Head" + DisableKeepAlive = $true + UseBasicParsing = $true + } + if (-not (Invoke-WebRequest @Parameters).StatusDescription) + { + return + } + + try + { + # Download Microsoft Edge Stable x64 + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + $Parameters = @{ + Uri = "https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&source=EdgeStablePage&Channel=Stable&language=$((Get-WinSystemLocale).TwoLetterISOLanguageName)" + OutFile = "$DownloadsFolder\MicrosoftEdgeSetup.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-Webrequest @Parameters + + # Install Microsoft Edge Stable x64 + Start-Process -FilePath "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Wait + + Get-Process -Name msedge | Stop-Process -Force -ErrorAction Ignore + Start-Sleep -Seconds 5 + + & "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe" --no-first-run --noerrdialogs --no-default-browser-check --start-maximized + + Remove-Item -Path "$DownloadsFolder\MicrosoftEdgeSetup.exe" -Force + + Start-Process -FilePath "https://t.me/sophia_chat" + Start-Process -FilePath "https://discord.gg/sSryhaEv79" + } + catch [System.Net.WebException] + { + Write-Warning -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") + Write-Error -Message ($Localization.NoResponse -f "https://c2rsetup.officeapps.live.com") -ErrorAction SilentlyContinue + } + } + catch [System.Net.WebException] + { + Write-Warning -Message $Localization.NoInternetConnection + Write-Error -Message $Localization.NoInternetConnection -ErrorAction SilentlyContinue + } + } + + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word + Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + + # Save all opened folders in order to restore them after File Explorer restart + $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() + # Display a warning message about whether a user has customized the preset file if ($Warning) { @@ -635,24 +719,6 @@ public static string GetString(uint strId) } } } - - # Enable back the SysMain service if it was disabled by harmful tweakers - if ((Get-Service -Name SysMain).Status -eq "Stopped") - { - Get-Service -Name SysMain | Set-Service -StartupType Automatic - Get-Service -Name SysMain | Start-Service - - Start-Process -FilePath "https://www.outsidethebox.ms/19318/" - } - - # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word - Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore - - # Import PowerShell 5.1 modules - Import-Module -Name Microsoft.PowerShell.Management, PackageManagement, Appx -UseWindowsPowerShell - - # Save all opened folders in order to restore them after File Explorer restart - $Script:OpenedFolders = {(New-Object -ComObject Shell.Application).Windows() | ForEach-Object -Process {$_.Document.Folder.Self.Path}}.Invoke() } #endregion Checks