diff --git a/Download_Latest_Sophia.ps1 b/Download_Latest_Sophia.ps1 index 193c7a85..3437315b 100644 --- a/Download_Latest_Sophia.ps1 +++ b/Download_Latest_Sophia.ps1 @@ -8,27 +8,12 @@ .EXAMPLE iwr sl.sophia.team -useb | iex #> + Clear-Host +$Global:Error.Clear() [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -# Checking whether the logged-in user is an admin -$CurrentUserName = (Get-CimInstance -ClassName Win32_Process -Filter ProcessId=$PID | Invoke-CimMethod -MethodName GetOwner | Select-Object -First 1).User -$LoginUserName = (Get-CimInstance -ClassName Win32_Process -Filter "name='explorer.exe'" | Invoke-CimMethod -MethodName GetOwner | Select-Object -First 1).User - -if ($CurrentUserName -ne $LoginUserName) -{ - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message "The logged-on user doesn't have admin rights." - Write-Information -MessageData "" -InformationAction Continue - - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - - pause - exit -} - if ($Host.Version.Major -eq 5) { # Progress bar can significantly impact cmdlet performance @@ -37,18 +22,40 @@ if ($Host.Version.Major -eq 5) } # https://github.com/PowerShell/PowerShell/issues/21070 -$Script:CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll") -$Script:CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new($env:TEMP, $false) +$Script:CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll") +$Script:CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new($env:TEMP, $false) $Script:CompilerParameters.GenerateInMemory = $true $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/archive/refs/heads/master.zip" - OutFile = "$DownloadsFolder\master.zip" - UseBasicParsing = $true - Verbose = $true + +try +{ + $Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/archive/refs/heads/master.zip" + OutFile = "$DownloadsFolder\master.zip" + UseBasicParsing = $true + Verbose = $true + } + Invoke-RestMethod @Parameters +} +catch [System.Net.WebException] +{ + Write-Warning -Message "github.com is unreachable. Please fix connection or change your DNS records." + Write-Information -MessageData "" -InformationAction Continue + + if ((Get-CimInstance -ClassName CIM_ComputerSystem).HypervisorPresent) + { + $DNS = (Get-NetRoute | Where-Object -FilterScript {$_.DestinationPrefix -eq "0.0.0.0/0"} | Get-NetAdapter | Where-Object -FilterScript {$_.Status -eq "Up"} | Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses + } + else + { + $DNS = (Get-NetAdapter -Physical | Where-Object -FilterScript {$_.Status -eq "Up"} | Get-NetIPInterface -AddressFamily IPv4 | Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses ### + } + Write-Warning -Message "You're using DNS $(if ($DNS.Count -gt 1) {$DNS -join ', '} else {$DNS})" + + pause + exit } -Invoke-RestMethod @Parameters switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) { @@ -58,7 +65,6 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName) -match "LTSC 2019") { $Version = "Sophia_Script_for_Windows_10_LTSC_2019" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } else { @@ -68,7 +74,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open the "Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" @@ -83,7 +89,6 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName) -match "LTSC 2021") { $Version = "Sophia_Script_for_Windows_10_LTSC_2021" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } else { @@ -93,7 +98,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open the "Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" @@ -107,12 +112,10 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) if ($Host.Version.Major -eq 5) { $Version = "Sophia_Script_for_Windows_10" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } else { $Version = "Sophia_Script_for_Windows_10_PowerShell_7" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 PowerShell 7 | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } } {$_ -ge 26100} @@ -125,12 +128,10 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) if ((Get-CimInstance -ClassName CIM_Processor).Caption -match "ARM") { $Version = "Sophia_Script_for_Windows_11_ARM" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 (Arm) | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } else { $Version = "Sophia_Script_for_Windows_11" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } } else @@ -138,19 +139,16 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) if ((Get-CimInstance -ClassName CIM_Processor).Caption -match "ARM") { $Version = "Sophia_Script_for_Windows_11_ARM_PowerShell_7" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 (Arm | PowerShell 7) | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } else { $Version = "Sophia_Script_for_Windows_11_PowerShell_7" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 (PowerShell) | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } } } else { $Version = "Sophia_Script_for_Windows_11_LTSC_2024" - $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 LTSC 2024 | Latest | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2025" } } } @@ -184,7 +182,7 @@ catch Write-Verbose -Message "Archive cannot be expanded. Probably, this was caused by your antivirus. Please update its definitions and try again." -Verbose # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open t"Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" diff --git a/Download_Sophia.ps1 b/Download_Sophia.ps1 index 1b402c09..361e8895 100644 --- a/Download_Sophia.ps1 +++ b/Download_Sophia.ps1 @@ -10,26 +10,10 @@ #> Clear-Host +$Global:Error.Clear() [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -# Checking whether the logged-in user is an admin -$CurrentUserName = (Get-CimInstance -ClassName Win32_Process -Filter ProcessId=$PID | Invoke-CimMethod -MethodName GetOwner | Select-Object -First 1).User -$LoginUserName = (Get-CimInstance -ClassName Win32_Process -Filter "name='explorer.exe'" | Invoke-CimMethod -MethodName GetOwner | Select-Object -First 1).User - -if ($CurrentUserName -ne $LoginUserName) -{ - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message "The logged-on user doesn't have admin rights." - Write-Information -MessageData "" -InformationAction Continue - - Write-Verbose -Message "https://t.me/sophia_chat" -Verbose - Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose - - pause - exit -} - if ($Host.Version.Major -eq 5) { # Progress bar can significantly impact cmdlet performance @@ -42,24 +26,26 @@ $Script:CompilerParameters = [System.CodeDom.Compiler.CompilerP $Script:CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new($env:TEMP, $false) $Script:CompilerParameters.GenerateInMemory = $true -$Parameters = @{ - Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest" - UseBasicParsing = $true +try +{ + $Parameters = @{ + Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest" + UseBasicParsing = $true + } + $LatestGitHubRelease = (Invoke-RestMethod @Parameters).tag_name } -$LatestGitHubRelease = (Invoke-RestMethod @Parameters).tag_name - -if (-not $LatestGitHubRelease) +catch [System.Net.WebException] { - Write-Warning -Message "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest is unreachable. Please fix connection or change your DNS records." + Write-Warning -Message "api.github.com is unreachable. Please fix connection or change your DNS records." Write-Information -MessageData "" -InformationAction Continue if ((Get-CimInstance -ClassName CIM_ComputerSystem).HypervisorPresent) { - $DNS = (Get-NetRoute | Where-Object -FilterScript {$_.DestinationPrefix -eq "0.0.0.0/0"} | Get-NetAdapter | Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses + $DNS = (Get-NetRoute | Where-Object -FilterScript {$_.DestinationPrefix -eq "0.0.0.0/0"} | Get-NetAdapter | Where-Object -FilterScript {$_.Status -eq "Up"} | Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses } else { - $DNS = (Get-NetAdapter -Physical | Get-NetIPInterface -AddressFamily IPv4 | Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses + $DNS = (Get-NetAdapter -Physical | Where-Object -FilterScript {$_.Status -eq "Up"} | Get-NetIPInterface -AddressFamily IPv4 | Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses } Write-Warning -Message "You're using DNS $(if ($DNS.Count -gt 1) {$DNS -join ', '} else {$DNS})" @@ -101,7 +87,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open the "Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" @@ -134,7 +120,7 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber) (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open the "Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" @@ -261,7 +247,7 @@ if (-not (Test-Path -Path "$DownloadsFolder\Sophia.Script.zip")) Write-Verbose -Message "Your Windows build is unsupported. Run Windows Update and try again." -Verbose # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open t"Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate" @@ -285,7 +271,7 @@ catch Write-Verbose -Message "Archive cannot be expanded. Probably, this was caused by your antivirus. Please update its definitions and try again." -Verbose # Check for updates - Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan + & "$env:SystemRoot\System32\UsoClient.exe" StartInteractiveScan # Open t"Windows Update" page Start-Process -FilePath "ms-settings:windowsupdate"