Skip to content

Commit

Permalink
Fixed CleanupTask -Register
Browse files Browse the repository at this point in the history
  • Loading branch information
farag2 committed Jun 15, 2024
1 parent 0772365 commit ca9be7b
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 57 deletions.
Binary file modified Wrapper/SophiaScriptWrapper.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion sophia_script_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"Sophia_Script_Windows_10_LTSC2021": "5.18.7",
"Sophia_Script_Windows_11_PowerShell_5_1": "6.6.7",
"Sophia_Script_Windows_11_PowerShell_7": "6.6.7",
"Sophia_Script_Wrapper": "2.7.0"
"Sophia_Script_Wrapper": "2.7.1"
}
63 changes: 51 additions & 12 deletions src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check the language mode
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage")
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedLanguageMode
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes" -Verbose
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Expand All @@ -175,7 +177,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);

if ($CurrentUserName -ne $LoginUserName)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.LoggedInUserNotAdmin
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -186,7 +190,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check whether the script was run via PowerShell 5.1
if ($PSVersionTable.PSVersion.Major -ne 5)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.UnsupportedPowerShell -f $PSVersionTable.PSVersion.Major, $PSVersionTable.PSVersion.Minor)
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -197,7 +203,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check whether the script was run in PowerShell ISE or VS Code
if (($Host.Name -match "ISE") -or ($env:TERM_PROGRAM -eq "vscode"))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.UnsupportedHost -f $Host.Name.Replace("Host", ""))
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand Down Expand Up @@ -248,7 +256,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
{
if ($Tweakers[$Tweaker] -eq "HKCU:\Software\Win 10 Tweaker")
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.Win10TweakerWarning
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://youtu.be/na93MS-1EkM" -Verbose
Write-Verbose -Message "https://pikabu.ru/story/byekdor_v_win_10_tweaker_ili_sovremennyie_metodyi_borbyi_s_piratstvom_8227558" -Verbose
Expand All @@ -258,7 +268,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
exit
}

Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.TweakerWarning -f $Tweaker)
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -278,7 +290,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
{
if ($Tweakers[$Tweaker])
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.TweakerWarning -f $Tweaker)
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -288,20 +302,26 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}

# Check whether Get-WindowsEdition cmdlet is working
# https://github.com/PowerShell/PowerShell/issues/21295
try
{
Get-WindowsEdition -Online
}
catch [System.Runtime.InteropServices.COMException]
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Get-WindowsEdition")
Write-Information -MessageData "" -InformationAction Continue

exit
}

# Check whether Windows Feature Experience Pack was removed by harmful tweakers
if (-not (Get-AppxPackage -Name MicrosoftWindows.Client.CBS))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Windows Feature Experience Pack")
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -312,8 +332,10 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check whether EventLog service is running in order to be sire that Event Logger is enabled
if ((Get-Service -Name EventLog).Status -eq "Stopped")
{
Write-Information -MessageData "" -InformationAction Continue
# Extract the localized "Event Viewer" string from shell32.dll
Write-Warning -Message ($Localization.WindowsComponentBroken -f $([WinAPI.GetStrings]::GetString(22029)))
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -324,7 +346,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check whether Microsoft Store being an important system component was removed
if (-not (Get-AppxPackage -Name Microsoft.WindowsStore))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Microsoft Store")
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -343,7 +367,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
{
if (-not (Test-Path -Path $File))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f $File)
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Expand All @@ -356,7 +382,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Checking whether Windows Security Settings page was hidden from UI
if ([Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer", "SettingsPageVisibility", $null) -match "hide:windowsdefender")
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Microsoft Defender")
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -372,8 +400,10 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
catch [Microsoft.Management.Infrastructure.CimException]
{
# Provider Load Failure exception
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Global:Error.Exception.Message | Select-Object -First 1
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Microsoft Defender")
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -384,7 +414,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check Microsoft Defender state
if ($null -eq (Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntiVirusProduct -ErrorAction Ignore))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Microsoft Defender")
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand All @@ -400,7 +432,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
}
catch [Microsoft.PowerShell.Commands.ServiceCommandException]
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.WindowsComponentBroken -f "Microsoft Defender")
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand Down Expand Up @@ -505,7 +539,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
)
if (($PendingActions | Test-Path) -contains $true)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.RebootPending
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand Down Expand Up @@ -541,7 +577,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);

if ([System.Version]$LatestRelease -gt [System.Version]$CurrentRelease)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedRelease
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Expand All @@ -565,7 +603,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Check whether LGPO.exe exists in the bin folder
if (-not (Test-Path -Path "$PSScriptRoot\..\bin\LGPO.exe"))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.Bin
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://github.com/farag2/Sophia-Script-for-Windows/releases/latest" -Verbose
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Expand All @@ -579,7 +619,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
{
{$_ -ne 19045}
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBuild
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand Down Expand Up @@ -647,7 +689,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# https://support.microsoft.com/en-us/topic/windows-10-update-history-8127c2c6-6edf-4fdf-8b9f-0f7be1ef3562
$CurrentBuild = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name CurrentBuild
$UBR = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name UBR
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message ($Localization.UpdateWarning -f $CurrentBuild.CurrentBuild, $UBR.UBR, $LatestSupportedBuild)
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand Down Expand Up @@ -1173,6 +1217,7 @@ function DiagTrackService
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message ($Localization.InitialActionsCheckFailed -f $PresetName) -Verbose
Write-Information -MessageData "" -InformationAction Continue

Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
Expand Down Expand Up @@ -11559,8 +11604,8 @@ function UninstallUWPApps
# Outlook
"Microsoft.OutlookForWindows",

# Chat (Microsoft Teams)
"MicrosoftTeams",
# Microsoft Teams
"MSTeams",

# Microsoft Copilot
"Microsoft.Windows.Ai.CoPilot.Provider"
Expand Down Expand Up @@ -12826,7 +12871,7 @@ while (`$true)
[int]`$CurrentMainWindowHandle = (Get-Process -Name cleanmgr | Where-Object -FilterScript {`$_.PriorityClass -eq """BelowNormal"""}).MainWindowHandle
if (`$SourceMainWindowHandle -ne `$CurrentMainWindowHandle)
{
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("""System.dll""")
`$CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new(`$env:TEMP, `$false)
`$CompilerParameters.GenerateInMemory = `$true
`$Signature = @{
Expand Down Expand Up @@ -12892,7 +12937,7 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
# https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs
# https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("""System.dll""")
`$CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new(`$env:TEMP, `$false)
`$CompilerParameters.GenerateInMemory = `$true
`$Signature = @{
Expand Down Expand Up @@ -13213,7 +13258,7 @@ function SoftwareDistributionTask
# https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs
# https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("""System.dll""")
`$CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new(`$env:TEMP, `$false)
`$CompilerParameters.GenerateInMemory = `$true
`$Signature = @{
Expand Down Expand Up @@ -13523,7 +13568,7 @@ function TempTask
# https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs
# https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("System.dll")
`$CompilerParameters = [System.CodeDom.Compiler.CompilerParameters]::new("""System.dll""")
`$CompilerParameters.TempFiles = [System.CodeDom.Compiler.TempFileCollection]::new(`$env:TEMP, `$false)
`$CompilerParameters.GenerateInMemory = `$true
`$Signature = @{
Expand Down Expand Up @@ -15409,12 +15454,6 @@ public static void PostMessage()
}
}

if ($Script:RegionChanged)
{
# Set the original region ID
Set-WinHomeLocation -GeoId $Script:Region
}

# Apply policies found in registry to re-build database database due to gpedit.msc relies in its own database
if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt"))
{
Expand Down
Loading

0 comments on commit ca9be7b

Please sign in to comment.