Skip to content

Commit 4728d05

Browse files
committed
Fixed downloading scripts
1 parent 64967d3 commit 4728d05

File tree

2 files changed

+13
-39
lines changed

2 files changed

+13
-39
lines changed

Download_Latest_Sophia.ps1

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,8 @@ switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber)
9090
{
9191
Write-Verbose -Message "Windows version is not supported. Update your Windows" -Verbose
9292

93-
# Get the real Windows version like %SystemRoot%\system32\winver.exe relies on
94-
$Signature = @{
95-
Namespace = "WinAPI"
96-
Name = "Winbrand"
97-
Language = "CSharp"
98-
CompilerParameters = $CompilerParameters
99-
MemberDefinition = @"
100-
[DllImport("Winbrand.dll", CharSet = CharSet.Unicode)]
101-
public extern static string BrandingFormatString(string sFormat);
102-
"@
103-
}
104-
105-
# PowerShell 7 has CompilerOptions argument instead of CompilerParameters as PowerShell 5 has
106-
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-type#-compileroptions
107-
if ($Host.Version.Major -eq 7)
108-
{
109-
$Signature.Remove("CompilerParameters")
110-
$Signature.Add("CompilerOptions", $CompilerParameters)
111-
}
112-
113-
if (-not ("WinAPI.Winbrand" -as [type]))
114-
{
115-
Add-Type @Signature
116-
}
117-
11893
# Receive updates for other Microsoft products when you update Windows
119-
if ([WinAPI.Winbrand]::BrandingFormatString("%WINDOWS_LONG%") -match "Windows 11")
120-
{
121-
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
122-
}
123-
else
124-
{
125-
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings -Name AllowMUUpdateService -PropertyType DWord -Value 1 -Force
126-
}
94+
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
12795

12896
# Check for updates
12997
Start-Process -FilePath "$env:SystemRoot\System32\UsoClient.exe" -ArgumentList StartInteractiveScan
@@ -315,8 +283,6 @@ switch ($Version)
315283
{
316284
Set-Location -Path "$DownloadsFolder\Sophia_Script_for_Windows_11_Latest"
317285
}
318-
319-
return
320286
}
321287
"Sophia_Script_for_Windows_11_PowerShell_7"
322288
{

Download_Sophia.ps1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,24 @@ if ($Host.Version.Major -eq 5)
3737
$Script:ProgressPreference = "SilentlyContinue"
3838
}
3939

40+
# https://github.com/PowerShell/PowerShell/issues/21070
41+
$Script:CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
42+
$Script:CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new($env:TEMP, $false)
43+
$Script:CompilerParameters.GenerateInMemory = $true
44+
4045
$Parameters = @{
4146
Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest"
4247
UseBasicParsing = $true
4348
}
4449
$LatestGitHubRelease = (Invoke-RestMethod @Parameters).tag_name
4550

51+
if (-not $LatestGitHubRelease)
52+
{
53+
Write-Warning -Message "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest is unreachable. Please fix connection."
54+
pause
55+
exit
56+
}
57+
4658
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
4759

4860
$Parameters = @{
@@ -288,10 +300,6 @@ switch ($Version)
288300
}
289301
}
290302

291-
# https://github.com/PowerShell/PowerShell/issues/21070
292-
$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
293-
$CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new($env:TEMP, $false)
294-
$CompilerParameters.GenerateInMemory = $true
295303
$Signature = @{
296304
Namespace = "WinAPI"
297305
Name = "ForegroundWindow"

0 commit comments

Comments
 (0)