diff --git a/Wrapper/Config/config_Windows_10.json b/Wrapper/Config/config_Windows_10.json index 246aecd8..d82013da 100644 --- a/Wrapper/Config/config_Windows_10.json +++ b/Wrapper/Config/config_Windows_10.json @@ -1634,9 +1634,6 @@ "Zero": { "Tag": "NET6x64" }, - "One": { - "Tag": "NET7x64" - }, "Two": { "Tag": "NET8x64" } @@ -2279,22 +2276,6 @@ "Preset": "", "WindowsDefault": "One" }, - { - "Region": "Context menu", - "Control": "cmb", - "Required": "false", - "Function": "ImagesEditContext", - "Arg": { - "Zero": { - "Tag": "Hide" - }, - "One": { - "Tag": "Show" - } - }, - "Preset": "Zero", - "WindowsDefault": "One" - }, { "Region": "Context menu", "Control": "cmb", diff --git a/Wrapper/Config/config_Windows_10_LTSC.json b/Wrapper/Config/config_Windows_10_LTSC.json index 42a3ad28..4219e4c1 100644 --- a/Wrapper/Config/config_Windows_10_LTSC.json +++ b/Wrapper/Config/config_Windows_10_LTSC.json @@ -1561,9 +1561,6 @@ "Zero": { "Tag": "NET6x64" }, - "One": { - "Tag": "NET7x64" - }, "Two": { "Tag": "NET8x64" } diff --git a/Wrapper/Config/config_Windows_11.json b/Wrapper/Config/config_Windows_11.json index 8c2e281c..714559bd 100644 --- a/Wrapper/Config/config_Windows_11.json +++ b/Wrapper/Config/config_Windows_11.json @@ -1560,9 +1560,6 @@ "Zero": { "Tag": "NET6x64" }, - "One": { - "Tag": "NET7x64" - }, "Two": { "Tag": "NET8x64" } diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_10.json b/Wrapper/Localizations/de-DE/tooltip_Windows_10.json index 8b362ea2..a02e8631 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_10.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_10.json @@ -1441,10 +1441,6 @@ "Tag": "NET6x64", "ToolTip": ".NET Desktop Runtime 6 x64." }, - "One": { - "Tag": "NET7x64", - "ToolTip": ".NET Desktop Runtime 7 x64." - }, "Two": { "Tag": "NET8x64", "ToolTip": ".NET Desktop Runtime 8 x64." diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json index 4f511e1f..fa7e47b1 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json @@ -1379,10 +1379,6 @@ "Tag": "NET6x64", "ToolTip": ".NET Desktop Runtime 6 x64." }, - "One": { - "Tag": "NET7x64", - "ToolTip": ".NET Desktop Runtime 7 x64." - }, "Two": { "Tag": "NET8x64", "ToolTip": ".NET Desktop Runtime 8 x64." diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_10.json b/Wrapper/Localizations/en-US/tooltip_Windows_10.json index a44e3ecb..9d6ce67c 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_10.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_10.json @@ -1441,10 +1441,6 @@ "Tag": "NET6x64", "ToolTip": ".NET Desktop Runtime 6 x64." }, - "One": { - "Tag": "NET7x64", - "ToolTip": ".NET Desktop Runtime 7 x64." - }, "Two": { "Tag": "NET8x64", "ToolTip": ".NET Desktop Runtime 8 x64." diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_11.json b/Wrapper/Localizations/en-US/tooltip_Windows_11.json index 781b814d..8a66d484 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_11.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_11.json @@ -1379,10 +1379,6 @@ "Tag": "NET6x64", "ToolTip": ".NET Desktop Runtime 6 x64." }, - "One": { - "Tag": "NET7x64", - "ToolTip": ".NET Desktop Runtime 7 x64." - }, "Two": { "Tag": "NET8x64", "ToolTip": ".NET Desktop Runtime 8 x64." diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json index c7a75083..4f9ba7ae 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json @@ -1441,10 +1441,6 @@ "Tag": "NET6x64", "ToolTip": ".NET Desktop Runtime 6 x64." }, - "One": { - "Tag": "NET7x64", - "ToolTip": ".NET Desktop Runtime 7 x64." - }, "Two": { "Tag": "NET8x64", "ToolTip": ".NET Desktop Runtime 8 x64." diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json index de30124c..2abe1552 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json @@ -1379,10 +1379,6 @@ "Tag": "NET6x64", "ToolTip": ".NET Desktop Runtime 6 x64." }, - "One": { - "Tag": "NET7x64", - "ToolTip": ".NET Desktop Runtime 7 x64." - }, "Two": { "Tag": "NET8x64", "ToolTip": ".NET Desktop Runtime 8 x64." diff --git a/Wrapper/SophiaScriptWrapper.exe b/Wrapper/SophiaScriptWrapper.exe index 67027754..2cf80c63 100644 Binary files a/Wrapper/SophiaScriptWrapper.exe and b/Wrapper/SophiaScriptWrapper.exe differ diff --git a/src/Sophia_Script_for_Windows_10/Functions.ps1 b/src/Sophia_Script_for_Windows_10/Functions.ps1 index 8fb750f1..5126faec 100644 --- a/src/Sophia_Script_for_Windows_10/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_10/Functions.ps1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -195,7 +194,7 @@ $Parameters = @{ continue } - # If a module command is UserFolders ### + # If a module command is UserFolders if ($Command -eq "UserFolders") { # Get all command arguments, excluding defaults diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 6d052b8f..75c39a69 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -36,6 +35,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #region InitialActions @@ -64,6 +64,7 @@ function InitialActions # Extract strings from %SystemRoot%\System32\shell32.dll using its' number # https://github.com/SamuelArnold/StarKill3r/blob/master/Star%20Killer/Star%20Killer/bin/Debug/Scripts/SANS-SEC505-master/scripts/Day1-PowerShell/Expand-IndirectString.ps1 + # [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100") $Signature = @{ Namespace = "WinAPI" Name = "GetStrings" @@ -841,33 +842,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } - # Register a temp schedule task to check whether there's a Windows bug presented - $Action = New-ScheduledTaskAction -Execute powershell.exe - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest - $Parameters = @{ - TaskName = "SophiaTempScheduledTask" - Principal = $Principal - Action = $Action - Settings = $Settings - } - try - { - Register-ScheduledTask @Parameters -Force -ErrorAction Stop - } - catch [Microsoft.Management.Infrastructure.CimException] - { - Write-Verbose -Message ($Localization.WindowsComponentBroken -f [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100")) -Verbose - - Start-Process -FilePath "https://t.me/sophia_chat" - Start-Process -FilePath "https://discord.gg/sSryhaEv79" - - exit - } - - # Remove temp schedule task - Unregister-ScheduledTask -TaskName SophiaTempScheduledTask -Confirm:$false -ErrorAction Ignore - # 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 @@ -5648,10 +5622,12 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false "@ # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "SymbolicLink" Principal = $Principal @@ -5770,10 +5746,12 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false "@ # Create a temporary scheduled task to clean up the temporary folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "TemporaryTask" Principal = $Principal @@ -10213,15 +10191,18 @@ function InstallVCRedist return } - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -10268,10 +10249,10 @@ function InstallVCRedist <# .SYNOPSIS - Install the latest .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 .EXAMPLE - InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 + InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 .LINK https://dotnet.microsoft.com/en-us/download/dotnet @@ -10288,7 +10269,7 @@ function InstallDotNetRuntimes Mandatory = $true, ParameterSetName = "Runtimes" )] - [ValidateSet("NET6x64", "NET7x64", "NET8x64")] + [ValidateSet("NET6x64", "NET8x64")] [string[]] $Runtimes ) @@ -10321,15 +10302,18 @@ function InstallDotNetRuntimes { NET6x64 { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -10363,60 +10347,19 @@ function InstallDotNetRuntimes Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } - NET7x64 - { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") - { - # https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/7 - # .NET Desktop Runtime 7 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.7 --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 - { - # .NET Desktop Runtime 7 - # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json - $Parameters = @{ - Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" - Verbose = $true - UseBasicParsing = $true - } - $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}" - - # .NET Desktop Runtime 7 x64 - $Parameters = @{ - Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" - OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - 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 ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # .NET Desktop Runtime 8 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements + 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 + # 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 { @@ -11550,7 +11493,7 @@ function UninstallUWPApps [PSCustomObject]@{ Name = $AppxPackage.Name PackageFullName = $AppxPackage.PackageFullName - # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display one the first one a window + # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display the first one DisplayName = $PackageId.DisplayName | Select-Object -First 1 } } @@ -12825,10 +12768,12 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); `$Process.Start() | Out-Null "@ - # Create the "Windows Cleanup" task + # Create "Windows Cleanup" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $CleanupTask" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "Windows Cleanup" TaskPath = "Sophia" @@ -12976,9 +12921,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force # Create the "Windows Cleanup Notification" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 30 -At 9pm $Parameters = @{ TaskName = "Windows Cleanup Notification" @@ -13286,9 +13233,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force # Create the "SoftwareDistribution" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9pm $Parameters = @{ TaskName = "SoftwareDistribution" @@ -13603,9 +13552,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force # Create the "Temp" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 60 -At 9pm $Parameters = @{ TaskName = "Temp" @@ -14723,66 +14674,6 @@ function EditWithPaint3DContext } } -<# - .SYNOPSIS - The "Edit" item in the images context menu - - .PARAMETER Hide - Hide the "Edit" item from the images context menu - - .PARAMETER Show - Show the "Edit" item in the images context menu - - .EXAMPLE - ImagesEditContext -Hide - - .EXAMPLE - ImagesEditContext -Show - - .NOTES - Current user -#> -function ImagesEditContext -{ - param - ( - [Parameter( - Mandatory = $true, - ParameterSetName = "Hide" - )] - [switch] - $Hide, - - [Parameter( - Mandatory = $true, - ParameterSetName = "Show" - )] - [switch] - $Show - ) - - if (-not ((Get-WindowsCapability -Online -Name "Microsoft.Windows.MSPaint*").State -eq "Installed")) - { - return - } - - switch ($PSCmdlet.ParameterSetName) - { - "Hide" - { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force - } - "Show" - { - Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit -Name ProgrammaticAccessOnly -Force -ErrorAction Ignore - } - } -} - <# .SYNOPSIS The "Print" item in the .bat and .cmd context menu diff --git a/src/Sophia_Script_for_Windows_10/Sophia.ps1 b/src/Sophia_Script_for_Windows_10/Sophia.ps1 index 48a9e0b7..67857f27 100644 --- a/src/Sophia_Script_for_Windows_10/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10/Sophia.ps1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -55,6 +54,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #Requires -RunAsAdministrator @@ -70,7 +70,7 @@ param Clear-Host -$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.18.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag & Inestic, 2014$([System.Char]0x2013)2024" +$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.18.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2024" Remove-Module -Name Sophia -Force -ErrorAction Ignore Import-LocalizedData -BindingVariable Global:Localization -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia @@ -1007,12 +1007,12 @@ UninstallPCHealthCheck InstallVCRedist <# - Install the latest .NET Desktop Runtime 6, 7, 8 x64 - Установить последнюю версию .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 + Установить последнюю версию .NET Desktop Runtime 6, 8 x64 https://dotnet.microsoft.com/en-us/download/dotnet #> -InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 +InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 # Enable proxying only blocked sites from the unified registry of Roskomnadzor. The function is applicable for Russia only # Включить проксирование только заблокированных сайтов из единого реестра Роскомнадзора. Функция применима только для России @@ -1389,14 +1389,6 @@ EditWithPaint3DContext -Hide # Отобразить пункт "Изменить с помощью Paint 3D" в контекстном меню медиа-файлов (значение по умолчанию) # EditWithPaint3DContext -Show -# Hide the "Edit" item from the images context menu -# Скрыть пункт "Изменить" из контекстного меню изображений -ImagesEditContext -Hide - -# Show the "Edit" item in images context menu (default value) -# Отобразить пункт "Изменить" в контекстном меню изображений (значение по умолчанию) -# ImagesEditContext -Show - # Hide the "Print" item from the .bat and .cmd context menu # Скрыть пункт "Печать" из контекстного меню .bat и .cmd файлов PrintCMDContext -Hide diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1 index fa3e4765..88688b3f 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1 @@ -5,8 +5,7 @@ Version: v5.8.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved 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 6d4fc2e9..6fbc967d 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 @@ -5,8 +5,7 @@ Version: v5.8.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -36,6 +35,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #region InitialActions @@ -64,6 +64,7 @@ function InitialActions # Extract strings from %SystemRoot%\System32\shell32.dll using its' number # https://github.com/SamuelArnold/StarKill3r/blob/master/Star%20Killer/Star%20Killer/bin/Debug/Scripts/SANS-SEC505-master/scripts/Day1-PowerShell/Expand-IndirectString.ps1 + # [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100") $Signature = @{ Namespace = "WinAPI" Name = "GetStrings" @@ -812,33 +813,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } - # Register a temp schedule task to check whether there's a Windows bug presented - $Action = New-ScheduledTaskAction -Execute powershell.exe - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest - $Parameters = @{ - TaskName = "SophiaTempScheduledTask" - Principal = $Principal - Action = $Action - Settings = $Settings - } - try - { - Register-ScheduledTask @Parameters -Force -ErrorAction Stop - } - catch [Microsoft.Management.Infrastructure.CimException] - { - Write-Verbose -Message ($Localization.WindowsComponentBroken -f [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100")) -Verbose - - Start-Process -FilePath "https://t.me/sophia_chat" - Start-Process -FilePath "https://discord.gg/sSryhaEv79" - - exit - } - - # Remove temp schedule task - Unregister-ScheduledTask -TaskName SophiaTempScheduledTask -Confirm:$false -ErrorAction Ignore - # 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 @@ -4373,10 +4347,12 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false "@ # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "SymbolicLink" Principal = $Principal @@ -4495,10 +4471,12 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false "@ # Create a temporary scheduled task to clean up the temporary folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "TemporaryTask" Principal = $Principal @@ -8526,15 +8504,18 @@ function InstallVCRedist return } - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -8581,10 +8562,10 @@ function InstallVCRedist <# .SYNOPSIS - Install the latest .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 .EXAMPLE - InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 + InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 .LINK https://dotnet.microsoft.com/en-us/download/dotnet @@ -8601,7 +8582,7 @@ function InstallDotNetRuntimes Mandatory = $true, ParameterSetName = "Runtimes" )] - [ValidateSet("NET6x64", "NET7x64", "NET8x64")] + [ValidateSet("NET6x64", "NET8x64")] [string[]] $Runtimes ) @@ -8634,15 +8615,18 @@ function InstallDotNetRuntimes { NET6x64 { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -8676,61 +8660,19 @@ function InstallDotNetRuntimes Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } - NET7x64 - { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") - { - # https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/7 - # .NET Desktop Runtime 7 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.7 --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 - { - # .NET Desktop Runtime 7 - # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json - $Parameters = @{ - Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" - Verbose = $true - UseBasicParsing = $true - } - $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}" - - # .NET Desktop Runtime 7 x64 - $Parameters = @{ - Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" - OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - 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 ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # .NET Desktop Runtime 8 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements + 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 + # 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 { @@ -9438,10 +9380,12 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); `$Process.Start() | Out-Null "@ - # Create the "Windows Cleanup" task + # Create "Windows Cleanup" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $CleanupTask" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "Windows Cleanup" TaskPath = "Sophia" @@ -9589,9 +9533,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force # Create the "Windows Cleanup Notification" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 30 -At 9pm $Parameters = @{ TaskName = "Windows Cleanup Notification" @@ -9899,9 +9845,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force # Create the "SoftwareDistribution" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9pm $Parameters = @{ TaskName = "SoftwareDistribution" @@ -10216,9 +10164,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force # Create the "Temp" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 60 -At 9pm $Parameters = @{ TaskName = "Temp" 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 a0f1ea8d..86cff616 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 @@ -5,8 +5,7 @@ Version: v5.8.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -55,6 +54,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #Requires -RunAsAdministrator @@ -70,7 +70,7 @@ param Clear-Host -$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.8.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag & Inestic, 2014$([System.Char]0x2013)2024" +$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.8.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2024" Remove-Module -Name Sophia -Force -ErrorAction Ignore Import-LocalizedData -BindingVariable Global:Localization -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia @@ -788,12 +788,12 @@ ActiveHours -Automatically InstallVCRedist <# - Install the latest .NET Desktop Runtime 6, 7, 8 x64 - Установить последнюю версию .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 + Установить последнюю версию .NET Desktop Runtime 6, 8 x64 https://dotnet.microsoft.com/en-us/download/dotnet #> -InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 +InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 # Enable proxying only blocked sites from the unified registry of Roskomnadzor. The function is applicable for Russia only # Включить проксирование только заблокированных сайтов из единого реестра Роскомнадзора. Функция применима только для России diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Functions.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Functions.ps1 index 2e27fc65..ece5dbc6 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Functions.ps1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved 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 566902ac..03132673 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 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -36,6 +35,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #region InitialActions @@ -64,6 +64,7 @@ function InitialActions # Extract strings from %SystemRoot%\System32\shell32.dll using its' number # https://github.com/SamuelArnold/StarKill3r/blob/master/Star%20Killer/Star%20Killer/bin/Debug/Scripts/SANS-SEC505-master/scripts/Day1-PowerShell/Expand-IndirectString.ps1 + # [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100") $Signature = @{ Namespace = "WinAPI" Name = "GetStrings" @@ -812,33 +813,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } - # Register a temp schedule task to check whether there's a Windows bug presented - $Action = New-ScheduledTaskAction -Execute powershell.exe - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest - $Parameters = @{ - TaskName = "SophiaTempScheduledTask" - Principal = $Principal - Action = $Action - Settings = $Settings - } - try - { - Register-ScheduledTask @Parameters -Force -ErrorAction Stop - } - catch [Microsoft.Management.Infrastructure.CimException] - { - Write-Verbose -Message ($Localization.WindowsComponentBroken -f [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100")) -Verbose - - Start-Process -FilePath "https://t.me/sophia_chat" - Start-Process -FilePath "https://discord.gg/sSryhaEv79" - - exit - } - - # Remove temp schedule task - Unregister-ScheduledTask -TaskName SophiaTempScheduledTask -Confirm:$false -ErrorAction Ignore - # 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 @@ -4745,10 +4719,12 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false "@ # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "SymbolicLink" Principal = $Principal @@ -4867,10 +4843,12 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false "@ # Create a temporary scheduled task to clean up the temporary folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "TemporaryTask" Principal = $Principal @@ -9153,15 +9131,18 @@ function InstallVCRedist return } - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -9208,10 +9189,10 @@ function InstallVCRedist <# .SYNOPSIS - Install the latest .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 .EXAMPLE - InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 + InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 .LINK https://dotnet.microsoft.com/en-us/download/dotnet @@ -9228,7 +9209,7 @@ function InstallDotNetRuntimes Mandatory = $true, ParameterSetName = "Runtimes" )] - [ValidateSet("NET6x64", "NET7x64", "NET8x64")] + [ValidateSet("NET6x64", "NET8x64")] [string[]] $Runtimes ) @@ -9261,15 +9242,18 @@ function InstallDotNetRuntimes { NET6x64 { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -9303,60 +9287,19 @@ function InstallDotNetRuntimes Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } - NET7x64 - { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") - { - # https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/7 - # .NET Desktop Runtime 7 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.7 --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 - { - # .NET Desktop Runtime 7 - # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json - $Parameters = @{ - Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" - Verbose = $true - UseBasicParsing = $true - } - $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}" - - # .NET Desktop Runtime 7 x64 - $Parameters = @{ - Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" - OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - 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 ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # .NET Desktop Runtime 8 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements + 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 + # 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 { @@ -10568,10 +10511,12 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); `$Process.Start() | Out-Null "@ - # Create the "Windows Cleanup" task + # Create "Windows Cleanup" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $CleanupTask" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "Windows Cleanup" TaskPath = "Sophia" @@ -10719,9 +10664,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force # Create the "Windows Cleanup Notification" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 30 -At 9pm $Parameters = @{ TaskName = "Windows Cleanup Notification" @@ -11029,9 +10976,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force # Create the "SoftwareDistribution" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9pm $Parameters = @{ TaskName = "SoftwareDistribution" @@ -11346,9 +11295,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force # Create the "Temp" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 60 -At 9pm $Parameters = @{ TaskName = "Temp" 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 4084d3fd..e666536d 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -55,6 +54,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #Requires -RunAsAdministrator @@ -70,7 +70,7 @@ param Clear-Host -$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 v5.18.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag & Inestic, 2014$([System.Char]0x2013)2024" +$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2021 v5.18.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2024" Remove-Module -Name Sophia -Force -ErrorAction Ignore Import-LocalizedData -BindingVariable Global:Localization -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia @@ -886,12 +886,12 @@ ActiveHours -Automatically InstallVCRedist <# - Install the latest .NET Desktop Runtime 6, 7, 8 x64 - Установить последнюю версию .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 + Установить последнюю версию .NET Desktop Runtime 6, 8 x64 https://dotnet.microsoft.com/en-us/download/dotnet #> -InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 +InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 # Enable proxying only blocked sites from the unified registry of Roskomnadzor. The function is applicable for Russia only # Включить проксирование только заблокированных сайтов из единого реестра Роскомнадзора. Функция применима только для России diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1 index d091a907..7aa8f1f2 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved 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 3ae451d3..c1773c6d 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 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -36,6 +35,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #region InitialActions @@ -60,6 +60,7 @@ function InitialActions # Extract strings from %SystemRoot%\System32\shell32.dll using its' number # https://github.com/SamuelArnold/StarKill3r/blob/master/Star%20Killer/Star%20Killer/bin/Debug/Scripts/SANS-SEC505-master/scripts/Day1-PowerShell/Expand-IndirectString.ps1 + # [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100") $Signature = @{ Namespace = "WinAPI" Name = "GetStrings" @@ -827,33 +828,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } - # Register a temp schedule task to check whether there's a Windows bug presented - $Action = New-ScheduledTaskAction -Execute powershell.exe - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest - $Parameters = @{ - TaskName = "SophiaTempScheduledTask" - Principal = $Principal - Action = $Action - Settings = $Settings - } - try - { - Register-ScheduledTask @Parameters -Force -ErrorAction Stop - } - catch [Microsoft.Management.Infrastructure.CimException] - { - Write-Verbose -Message ($Localization.WindowsComponentBroken -f [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100")) -Verbose - - Start-Process -FilePath "https://t.me/sophia_chat" - Start-Process -FilePath "https://discord.gg/sSryhaEv79" - - exit - } - - # Remove temp schedule task - Unregister-ScheduledTask -TaskName SophiaTempScheduledTask -Confirm:$false -ErrorAction Ignore - # 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 @@ -5637,10 +5611,12 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false "@ # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "SymbolicLink" Principal = $Principal @@ -5759,10 +5735,12 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false "@ # Create a temporary scheduled task to clean up the temporary folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "TemporaryTask" Principal = $Principal @@ -10202,15 +10180,18 @@ function InstallVCRedist return } - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -10257,10 +10238,10 @@ function InstallVCRedist <# .SYNOPSIS - Install the latest .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 .EXAMPLE - InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 + InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 .LINK https://dotnet.microsoft.com/en-us/download/dotnet @@ -10277,7 +10258,7 @@ function InstallDotNetRuntimes Mandatory = $true, ParameterSetName = "Runtimes" )] - [ValidateSet("NET6x64", "NET7x64", "NET8x64")] + [ValidateSet("NET6x64", "NET8x64")] [string[]] $Runtimes ) @@ -10310,15 +10291,18 @@ function InstallDotNetRuntimes { NET6x64 { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -10352,60 +10336,19 @@ function InstallDotNetRuntimes Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } - NET7x64 - { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") - { - # https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/7 - # .NET Desktop Runtime 7 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.7 --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 - { - # .NET Desktop Runtime 7 - # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json - $Parameters = @{ - Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" - Verbose = $true - UseBasicParsing = $true - } - $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}" - - # .NET Desktop Runtime 7 x64 - $Parameters = @{ - Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" - OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - 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 ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # .NET Desktop Runtime 8 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements + 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 + # 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 { @@ -11549,7 +11492,7 @@ function UninstallUWPApps [PSCustomObject]@{ Name = $AppxPackage.Name PackageFullName = $AppxPackage.PackageFullName - # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display one the first one a window + # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display the first one DisplayName = $PackageId.DisplayName | Select-Object -First 1 } } @@ -12834,10 +12777,12 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); `$Process.Start() | Out-Null "@ - # Create the "Windows Cleanup" task + # Create "Windows Cleanup" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $CleanupTask" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "Windows Cleanup" TaskPath = "Sophia" @@ -12985,9 +12930,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force # Create the "Windows Cleanup Notification" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 30 -At 9pm $Parameters = @{ TaskName = "Windows Cleanup Notification" @@ -13295,9 +13242,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force # Create the "SoftwareDistribution" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9pm $Parameters = @{ TaskName = "SoftwareDistribution" @@ -13612,9 +13561,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force # Create the "Temp" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 60 -At 9pm $Parameters = @{ TaskName = "Temp" @@ -14732,66 +14683,6 @@ function EditWithPaint3DContext } } -<# - .SYNOPSIS - The "Edit" item in the images context menu - - .PARAMETER Hide - Hide the "Edit" item from the images context menu - - .PARAMETER Show - Show the "Edit" item in the images context menu - - .EXAMPLE - ImagesEditContext -Hide - - .EXAMPLE - ImagesEditContext -Show - - .NOTES - Current user -#> -function ImagesEditContext -{ - param - ( - [Parameter( - Mandatory = $true, - ParameterSetName = "Hide" - )] - [switch] - $Hide, - - [Parameter( - Mandatory = $true, - ParameterSetName = "Show" - )] - [switch] - $Show - ) - - if (-not ((Get-WindowsCapability -Online -Name "Microsoft.Windows.MSPaint*").State -eq "Installed")) - { - return - } - - switch ($PSCmdlet.ParameterSetName) - { - "Hide" - { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit -Name ProgrammaticAccessOnly -PropertyType String -Value "" -Force - } - "Show" - { - Remove-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit -Name ProgrammaticAccessOnly -Force -ErrorAction Ignore - } - } -} - <# .SYNOPSIS The "Print" item in the .bat and .cmd context menu 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 23957928..be7fb42a 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 @@ -5,8 +5,7 @@ Version: v5.18.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -55,6 +54,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #Requires -RunAsAdministrator @@ -70,7 +70,7 @@ param Clear-Host -$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.18.2 (PowerShell 7) | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag & Inestic, 2014$([System.Char]0x2013)2024" +$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.18.2 (PowerShell 7) | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2024" # PowerShell 7 doesn't load en-us localization automatically if there is no localization folder in user's language which is determined by $PSUICulture # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-localizeddata?view=powershell-7.3 @@ -1016,12 +1016,12 @@ UninstallPCHealthCheck InstallVCRedist <# - Install the latest .NET Desktop Runtime 6, 7, 8 x64 - Установить последнюю версию .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 + Установить последнюю версию .NET Desktop Runtime 6, 8 x64 https://dotnet.microsoft.com/en-us/download/dotnet #> -InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 +InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 # Enable proxying only blocked sites from the unified registry of Roskomnadzor. The function is applicable for Russia only # Включить проксирование только заблокированных сайтов из единого реестра Роскомнадзора. Функция применима только для России @@ -1398,14 +1398,6 @@ EditWithPaint3DContext -Hide # Отобразить пункт "Изменить с помощью Paint 3D" в контекстном меню медиа-файлов (значение по умолчанию) # EditWithPaint3DContext -Show -# Hide the "Edit" item from the images context menu -# Скрыть пункт "Изменить" из контекстного меню изображений -ImagesEditContext -Hide - -# Show the "Edit" item in images context menu (default value) -# Отобразить пункт "Изменить" в контекстном меню изображений (значение по умолчанию) -# ImagesEditContext -Show - # Hide the "Print" item from the .bat and .cmd context menu # Скрыть пункт "Печать" из контекстного меню .bat и .cmd файлов PrintCMDContext -Hide diff --git a/src/Sophia_Script_for_Windows_11/Functions.ps1 b/src/Sophia_Script_for_Windows_11/Functions.ps1 index 0e24f5a2..a3b8bc16 100644 --- a/src/Sophia_Script_for_Windows_11/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_11/Functions.ps1 @@ -5,8 +5,7 @@ Version: v6.6.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 38b9d167..64e34ccb 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -5,8 +5,7 @@ Version: v6.6.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -35,6 +34,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #region InitialActions @@ -63,6 +63,7 @@ function InitialActions # Extract strings from %SystemRoot%\System32\shell32.dll using its' number # https://github.com/SamuelArnold/StarKill3r/blob/master/Star%20Killer/Star%20Killer/bin/Debug/Scripts/SANS-SEC505-master/scripts/Day1-PowerShell/Expand-IndirectString.ps1 + # [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100") $Signature = @{ Namespace = "WinAPI" Name = "GetStrings" @@ -610,7 +611,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); DnsOnly = $true ErrorAction = "Stop" } - if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") ### + if ((Resolve-DnsName @Parameters).IPAddress -notcontains "131.107.255.255") { return } @@ -814,33 +815,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } - # Register a temp schedule task to check whether there's a Windows bug presented - $Action = New-ScheduledTaskAction -Execute powershell.exe - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest - $Parameters = @{ - TaskName = "SophiaTempScheduledTask" - Principal = $Principal - Action = $Action - Settings = $Settings - } - try - { - Register-ScheduledTask @Parameters -Force -ErrorAction Stop - } - catch [Microsoft.Management.Infrastructure.CimException] - { - Write-Verbose -Message ($Localization.WindowsComponentBroken -f [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100")) -Verbose - - Start-Process -FilePath "https://t.me/sophia_chat" - Start-Process -FilePath "https://discord.gg/sSryhaEv79" - - exit - } - - # Remove temp schedule task - Unregister-ScheduledTask -TaskName SophiaTempScheduledTask -Confirm:$false -ErrorAction Ignore - # 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 @@ -5246,10 +5220,12 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false "@ # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "SymbolicLink" Principal = $Principal @@ -5368,10 +5344,12 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false "@ # Create a temporary scheduled task to clean up the temporary folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "TemporaryTask" Principal = $Principal @@ -9837,15 +9815,18 @@ function InstallVCRedist return } - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -9892,10 +9873,10 @@ function InstallVCRedist <# .SYNOPSIS - Install the latest .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 .EXAMPLE - InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 + InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 .LINK https://dotnet.microsoft.com/en-us/download/dotnet @@ -9912,7 +9893,7 @@ function InstallDotNetRuntimes Mandatory = $true, ParameterSetName = "Runtimes" )] - [ValidateSet("NET6x64", "NET7x64", "NET8x64")] + [ValidateSet("NET6x64", "NET8x64")] [string[]] $Runtimes ) @@ -9945,15 +9926,18 @@ function InstallDotNetRuntimes { NET6x64 { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -9987,61 +9971,19 @@ function InstallDotNetRuntimes Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } - NET7x64 - { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") - { - # https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/7 - # .NET Desktop Runtime 7 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.7 --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 - { - # .NET Desktop Runtime 7 - # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json - $Parameters = @{ - Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" - Verbose = $true - UseBasicParsing = $true - } - $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}" - - # .NET Desktop Runtime 7 x64 - $Parameters = @{ - Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" - OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - 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 ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # .NET Desktop Runtime 8 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements + 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 + # 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 { @@ -11025,7 +10967,10 @@ function UninstallUWPApps "Microsoft.OutlookForWindows", # Chat (Microsoft Teams) - "MicrosoftTeams" + "MicrosoftTeams", + + # Microsoft Copilot + "Microsoft.Windows.Ai.CoPilot.Provider" ) foreach ($Package in $Packages) { @@ -11047,7 +10992,7 @@ function UninstallUWPApps [PSCustomObject]@{ Name = $AppxPackage.Name PackageFullName = $AppxPackage.PackageFullName - # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display one the first one a window + # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display the first one DisplayName = $PackageId.DisplayName | Select-Object -First 1 } } @@ -12155,10 +12100,12 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); `$Process.Start() | Out-Null "@ - # Create the "Windows Cleanup" task + # Create "Windows Cleanup" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $CleanupTask" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "Windows Cleanup" TaskPath = "Sophia" @@ -12306,9 +12253,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force # Create the "Windows Cleanup Notification" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 30 -At 9pm $Parameters = @{ TaskName = "Windows Cleanup Notification" @@ -12616,9 +12565,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force # Create the "SoftwareDistribution" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9pm $Parameters = @{ TaskName = "SoftwareDistribution" @@ -12933,9 +12884,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force # Create the "Temp" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 60 -At 9pm $Parameters = @{ TaskName = "Temp" diff --git a/src/Sophia_Script_for_Windows_11/Sophia.ps1 b/src/Sophia_Script_for_Windows_11/Sophia.ps1 index 54fcaec8..dc6a14c0 100644 --- a/src/Sophia_Script_for_Windows_11/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11/Sophia.ps1 @@ -5,8 +5,7 @@ Version: v6.6.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -54,6 +53,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #Requires -RunAsAdministrator @@ -69,7 +69,7 @@ param Clear-Host -$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.6.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag & Inestic, 2014$([System.Char]0x2013)2024" +$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.6.2 | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2024" Remove-Module -Name Sophia -Force -ErrorAction Ignore Import-LocalizedData -BindingVariable Global:Localization -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia @@ -979,12 +979,12 @@ DefaultTerminalApp -WindowsTerminal InstallVCRedist <# - Install the latest .NET Desktop Runtime 6, 7, 8 x64 - Установить последнюю версию .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 + Установить последнюю версию .NET Desktop Runtime 6, 8 x64 https://dotnet.microsoft.com/en-us/download/dotnet #> -InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 +InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 # Enable proxying only blocked sites from the unified registry of Roskomnadzor. The function is applicable for Russia only # Включить проксирование только заблокированных сайтов из единого реестра Роскомнадзора. Функция применима только для России diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1 index 60b62a1c..7ecf94c6 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1 @@ -5,8 +5,7 @@ Version: v6.6.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved 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 ee072f70..e8009298 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 @@ -5,8 +5,7 @@ Version: v6.6.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -35,6 +34,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #region InitialActions @@ -59,6 +59,7 @@ function InitialActions # Extract strings from %SystemRoot%\System32\shell32.dll using its' number # https://github.com/SamuelArnold/StarKill3r/blob/master/Star%20Killer/Star%20Killer/bin/Debug/Scripts/SANS-SEC505-master/scripts/Day1-PowerShell/Expand-IndirectString.ps1 + # [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100") $Signature = @{ Namespace = "WinAPI" Name = "GetStrings" @@ -803,33 +804,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue } - # Register a temp schedule task to check whether there's a Windows bug presented - $Action = New-ScheduledTaskAction -Execute powershell.exe - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest - $Parameters = @{ - TaskName = "SophiaTempScheduledTask" - Principal = $Principal - Action = $Action - Settings = $Settings - } - try - { - Register-ScheduledTask @Parameters -Force -ErrorAction Stop - } - catch [Microsoft.Management.Infrastructure.CimException] - { - Write-Verbose -Message ($Localization.WindowsComponentBroken -f [WinAPI.GetStrings]::GetIndirectString("@%SystemRoot%\system32\schedsvc.dll,-100")) -Verbose - - Start-Process -FilePath "https://t.me/sophia_chat" - Start-Process -FilePath "https://discord.gg/sSryhaEv79" - - exit - } - - # Remove temp schedule task - Unregister-ScheduledTask -TaskName SophiaTempScheduledTask -Confirm:$false -ErrorAction Ignore - # 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 @@ -5235,10 +5209,12 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false "@ # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "SymbolicLink" Principal = $Principal @@ -5357,10 +5333,12 @@ Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false "@ # Create a temporary scheduled task to clean up the temporary folder + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "TemporaryTask" Principal = $Principal @@ -9826,15 +9804,18 @@ function InstallVCRedist return } - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -9881,10 +9862,10 @@ function InstallVCRedist <# .SYNOPSIS - Install the latest .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 .EXAMPLE - InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 + InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 .LINK https://dotnet.microsoft.com/en-us/download/dotnet @@ -9901,7 +9882,7 @@ function InstallDotNetRuntimes Mandatory = $true, ParameterSetName = "Runtimes" )] - [ValidateSet("NET6x64", "NET7x64", "NET8x64")] + [ValidateSet("NET6x64", "NET8x64")] [string[]] $Runtimes ) @@ -9934,15 +9915,18 @@ function InstallDotNetRuntimes { NET6x64 { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # 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 + 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 + # 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 { @@ -9976,60 +9960,19 @@ function InstallDotNetRuntimes Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } - NET7x64 - { - if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") - { - # https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/DotNet/DesktopRuntime/7 - # .NET Desktop Runtime 7 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.7 --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 - { - # .NET Desktop Runtime 7 - # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json - $Parameters = @{ - Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" - Verbose = $true - UseBasicParsing = $true - } - $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}" - - # .NET Desktop Runtime 7 x64 - $Parameters = @{ - Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" - OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" - UseBasicParsing = $true - Verbose = $true - } - Invoke-WebRequest @Parameters - - 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 ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") + if (Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore) { - # .NET Desktop Runtime 8 x64 - winget install --id=Microsoft.DotNet.DesktopRuntime.8 --architecture x64 --exact --force --accept-source-agreements + 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 + # 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 { @@ -11023,7 +10966,10 @@ function UninstallUWPApps "Microsoft.OutlookForWindows", # Chat (Microsoft Teams) - "MicrosoftTeams" + "MicrosoftTeams", + + # Microsoft Copilot + "Microsoft.Windows.Ai.CoPilot.Provider" ) foreach ($Package in $Packages) { @@ -11045,7 +10991,7 @@ function UninstallUWPApps [PSCustomObject]@{ Name = $AppxPackage.Name PackageFullName = $AppxPackage.PackageFullName - # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display one the first one a window + # Sometimes there's more than one package presented in Windows with the same package name like {Microsoft Teams, Microsoft Teams} and we need to display the first one DisplayName = $PackageId.DisplayName | Select-Object -First 1 } } @@ -12163,10 +12109,12 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); `$Process.Start() | Out-Null "@ - # Create the "Windows Cleanup" task + # Create "Windows Cleanup" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $CleanupTask" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ TaskName = "Windows Cleanup" TaskPath = "Sophia" @@ -12314,9 +12262,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force # Create the "Windows Cleanup Notification" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 30 -At 9pm $Parameters = @{ TaskName = "Windows Cleanup Notification" @@ -12624,9 +12574,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force # Create the "SoftwareDistribution" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 90 -At 9pm $Parameters = @{ TaskName = "SoftwareDistribution" @@ -12941,9 +12893,11 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force # Create the "Temp" task + # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method + # https://github.com/PowerShell/PowerShell/issues/21377 $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable - $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest + $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 60 -At 9pm $Parameters = @{ TaskName = "Temp" 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 7f8a6dc7..5e727312 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 @@ -5,8 +5,7 @@ Version: v6.6.2 Date: 06.03.2024 - Copyright (c) 2014—2024 farag - Copyright (c) 2019—2024 farag & Inestic + Copyright (c) 2014—2024 farag, Inestic & lowl1f3 Thanks to all https://forum.ru-board.com members involved @@ -54,6 +53,7 @@ .LINK Authors https://github.com/farag2 https://github.com/Inestic + https://github.com/lowl1f3 #> #Requires -RunAsAdministrator @@ -69,7 +69,7 @@ param Clear-Host -$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.6.2 (PowerShell 7) | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag & Inestic, 2014$([System.Char]0x2013)2024" +$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.6.2 (PowerShell 7) | Made with $([System.Char]::ConvertFromUtf32(0x1F497)) of Windows | $([System.Char]0x00A9) farag, Inestic & lowl1f3, 2014$([System.Char]0x2013)2024" Remove-Module -Name Sophia -Force -ErrorAction Ignore @@ -990,12 +990,12 @@ DefaultTerminalApp -WindowsTerminal InstallVCRedist <# - Install the latest .NET Desktop Runtime 6, 7, 8 x64 - Установить последнюю версию .NET Desktop Runtime 6, 7, 8 x64 + Install the latest .NET Desktop Runtime 6, 8 x64 + Установить последнюю версию .NET Desktop Runtime 6, 8 x64 https://dotnet.microsoft.com/en-us/download/dotnet #> -InstallDotNetRuntimes -Runtimes NET6x64, NET7x64, NET8x64 +InstallDotNetRuntimes -Runtimes NET6x64, NET8x64 # Enable proxying only blocked sites from the unified registry of Roskomnadzor. The function is applicable for Russia only # Включить проксирование только заблокированных сайтов из единого реестра Роскомнадзора. Функция применима только для России