Browse Source

Fixed downloading scripts

master
Dmitry Nefedov 1 month ago
parent
commit
4728d05348
  1. 36
      Download_Latest_Sophia.ps1
  2. 16
      Download_Sophia.ps1

36
Download_Latest_Sophia.ps1

@ -90,40 +90,8 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber)
{ {
Write-Verbose -Message "Windows version is not supported. Update your Windows" -Verbose Write-Verbose -Message "Windows version is not supported. Update your Windows" -Verbose
# Get the real Windows version like %SystemRoot%\system32\winver.exe relies on
$Signature = @{
Namespace = "WinAPI"
Name = "Winbrand"
Language = "CSharp"
CompilerParameters = $CompilerParameters
MemberDefinition = @"
[DllImport("Winbrand.dll", CharSet = CharSet.Unicode)]
public extern static string BrandingFormatString(string sFormat);
"@
}
# PowerShell 7 has CompilerOptions argument instead of CompilerParameters as PowerShell 5 has
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-type#-compileroptions
if ($Host.Version.Major -eq 7)
{
$Signature.Remove("CompilerParameters")
$Signature.Add("CompilerOptions", $CompilerParameters)
}
if (-not ("WinAPI.Winbrand" -as [type]))
{
Add-Type @Signature
}
# Receive updates for other Microsoft products when you update Windows # Receive updates for other Microsoft products when you update Windows
if ([WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") -match "Windows 11") (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
{
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
}
else
{
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name AllowMUUpdateService -PropertyType DWord -Value 1 -Force
}
# Check for updates # Check for updates
Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan
@ -315,8 +283,6 @@ switch ($Version)
{ {
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_Latest" Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_Latest"
} }
return
} }
"Sophia_Script_for_Windows_11_PowerShell_7" "Sophia_Script_for_Windows_11_PowerShell_7"
{ {

16
Download_Sophia.ps1

@ -37,12 +37,24 @@ if ($Host.Version.Major -eq 5)
$Script:ProgressPreference = "SilentlyContinue" $Script:ProgressPreference = "SilentlyContinue"
} }
# 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.GenerateInMemory = $true
$Parameters = @{ $Parameters = @{
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest" Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest"
UseBasicParsing = $true UseBasicParsing = $true
} }
$LatestGitHubRelease = (Invoke-RestMethod @Parameters).tag_name $LatestGitHubRelease = (Invoke-RestMethod @Parameters).tag_name
if (-not $LatestGitHubRelease)
{
Write-Warning -Message "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest is unreachable. Please fix connection."
pause
exit
}
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
$Parameters = @{ $Parameters = @{
@ -288,10 +300,6 @@ switch ($Version)
} }
} }
# https://github.com/PowerShell/PowerShell/issues/21070
$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
$CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new($env:TEMP, $false)
$CompilerParameters.GenerateInMemory = $true
$Signature = @{ $Signature = @{
Namespace = "WinAPI" Namespace = "WinAPI"
Name = "ForegroundWindow" Name = "ForegroundWindow"

Loading…
Cancel
Save