diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 7f02e998..583cdff8 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -241,8 +241,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinCry = "$env:SystemRoot\TempCleaner.exe" # https://hone.gg Hone = "$env:LOCALAPPDATA\Programs\Hone\Hone.exe" - # https://github.com/ChrisTitusTech/winutil - winutil = "$env:TEMP\Winutil.log" # https://www.youtube.com/watch?v=5NBqbUUB1Pk WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas @@ -12264,11 +12262,14 @@ function CleanupTask New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force $CleanupTask = @" +# https://github.com/farag2/Sophia-Script-for-Windows +# https://t.me/sophia_chat + Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """$env:SystemRoot\System32\cleanmgr.exe""" -`$ProcessInfo.Arguments = """/sagerun:1337""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\cleanmgr.exe" +`$ProcessInfo.Arguments = "/sagerun:1337" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -12279,8 +12280,8 @@ Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force Start-Sleep -Seconds 3 `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """`$env:SystemRoot\System32\Dism.exe""" -`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\Dism.exe" +`$ProcessInfo.Arguments = "/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -12289,10 +12290,28 @@ Start-Sleep -Seconds 3 `$Process.Start() | Out-Null "@ + # Save script to be able to call them from VBS file + if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) + { + New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force + } + # Save in UTF8 with BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + + # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + $CleanupTask = @" +' https://github.com/farag2/Sophia-Script-for-Windows +' https://t.me/sophia_chat + +CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 +"@ + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + # 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" + $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ @@ -12426,17 +12445,12 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show(`$ToastMessage) "@ - # Save script to be able to call them from VBS file - if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) - { - New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force - } # Save in UTF8 with BOM Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force - # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up $ToastNotification = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat @@ -12463,12 +12477,18 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro } Register-ScheduledTask @Parameters -Force + # Start Task Scheduler in the end if any scheduled task was created $Script:ScheduledTasks = $true } "Delete" { # Remove files first unless we cannot remove folder if there's no more tasks there - Remove-Item -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Force -ErrorAction Ignore + $Paths = @( + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" + ) + Remove-Item -Path $Paths -Force -ErrorAction Ignore # Remove all old tasks # We have to use -ErrorAction Ignore in both cases, unless we get an error 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 89c66385..440c420e 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 @@ -241,8 +241,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinCry = "$env:SystemRoot\TempCleaner.exe" # https://hone.gg Hone = "$env:LOCALAPPDATA\Programs\Hone\Hone.exe" - # https://github.com/ChrisTitusTech/winutil - winutil = "$env:TEMP\Winutil.log" # https://www.youtube.com/watch?v=5NBqbUUB1Pk WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas @@ -9118,11 +9116,14 @@ function CleanupTask New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force $CleanupTask = @" +# https://github.com/farag2/Sophia-Script-for-Windows +# https://t.me/sophia_chat + Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """$env:SystemRoot\System32\cleanmgr.exe""" -`$ProcessInfo.Arguments = """/sagerun:1337""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\cleanmgr.exe" +`$ProcessInfo.Arguments = "/sagerun:1337" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -9133,8 +9134,8 @@ Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force Start-Sleep -Seconds 3 `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """`$env:SystemRoot\System32\Dism.exe""" -`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\Dism.exe" +`$ProcessInfo.Arguments = "/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -9143,10 +9144,28 @@ Start-Sleep -Seconds 3 `$Process.Start() | Out-Null "@ + # Save script to be able to call them from VBS file + if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) + { + New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force + } + # Save in UTF8 with BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + + # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + $CleanupTask = @" +' https://github.com/farag2/Sophia-Script-for-Windows +' https://t.me/sophia_chat + +CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 +"@ + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + # 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" + $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ @@ -9280,17 +9299,12 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show(`$ToastMessage) "@ - # Save script to be able to call them from VBS file - if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) - { - New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force - } # Save in UTF8 with BOM Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force - # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up $ToastNotification = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat @@ -9317,12 +9331,18 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro } Register-ScheduledTask @Parameters -Force + # Start Task Scheduler in the end if any scheduled task was created $Script:ScheduledTasks = $true } "Delete" { # Remove files first unless we cannot remove folder if there's no more tasks there - Remove-Item -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Force -ErrorAction Ignore + $Paths = @( + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" + ) + Remove-Item -Path $Paths -Force -ErrorAction Ignore # Remove all old tasks # We have to use -ErrorAction Ignore in both cases, unless we get an error 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 8dad0664..2450f30c 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 @@ -241,8 +241,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinCry = "$env:SystemRoot\TempCleaner.exe" # https://hone.gg Hone = "$env:LOCALAPPDATA\Programs\Hone\Hone.exe" - # https://github.com/ChrisTitusTech/winutil - winutil = "$env:TEMP\Winutil.log" # https://www.youtube.com/watch?v=5NBqbUUB1Pk WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas @@ -10251,11 +10249,14 @@ function CleanupTask New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force $CleanupTask = @" +# https://github.com/farag2/Sophia-Script-for-Windows +# https://t.me/sophia_chat + Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """$env:SystemRoot\System32\cleanmgr.exe""" -`$ProcessInfo.Arguments = """/sagerun:1337""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\cleanmgr.exe" +`$ProcessInfo.Arguments = "/sagerun:1337" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -10266,8 +10267,8 @@ Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force Start-Sleep -Seconds 3 `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """`$env:SystemRoot\System32\Dism.exe""" -`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\Dism.exe" +`$ProcessInfo.Arguments = "/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -10276,10 +10277,28 @@ Start-Sleep -Seconds 3 `$Process.Start() | Out-Null "@ + # Save script to be able to call them from VBS file + if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) + { + New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force + } + # Save in UTF8 with BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + + # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + $CleanupTask = @" +' https://github.com/farag2/Sophia-Script-for-Windows +' https://t.me/sophia_chat + +CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 +"@ + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + # 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" + $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ @@ -10413,17 +10432,12 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show(`$ToastMessage) "@ - # Save script to be able to call them from VBS file - if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) - { - New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force - } # Save in UTF8 with BOM Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force - # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up $ToastNotification = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat @@ -10450,12 +10464,18 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro } Register-ScheduledTask @Parameters -Force + # Start Task Scheduler in the end if any scheduled task was created $Script:ScheduledTasks = $true } "Delete" { # Remove files first unless we cannot remove folder if there's no more tasks there - Remove-Item -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Force -ErrorAction Ignore + $Paths = @( + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" + ) + Remove-Item -Path $Paths -Force -ErrorAction Ignore # Remove all old tasks # We have to use -ErrorAction Ignore in both cases, unless we get an error 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 f31cb578..8199c77c 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 @@ -240,8 +240,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinCry = "$env:SystemRoot\TempCleaner.exe" # https://hone.gg Hone = "$env:LOCALAPPDATA\Programs\Hone\Hone.exe" - # https://github.com/ChrisTitusTech/winutil - winutil = "$env:TEMP\Winutil.log" # https://www.youtube.com/watch?v=5NBqbUUB1Pk WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas @@ -12280,11 +12278,14 @@ function CleanupTask New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force $CleanupTask = @" +# https://github.com/farag2/Sophia-Script-for-Windows +# https://t.me/sophia_chat + Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """$env:SystemRoot\System32\cleanmgr.exe""" -`$ProcessInfo.Arguments = """/sagerun:1337""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\cleanmgr.exe" +`$ProcessInfo.Arguments = "/sagerun:1337" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -12295,8 +12296,8 @@ Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force Start-Sleep -Seconds 3 `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """`$env:SystemRoot\System32\Dism.exe""" -`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\Dism.exe" +`$ProcessInfo.Arguments = "/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -12305,10 +12306,28 @@ Start-Sleep -Seconds 3 `$Process.Start() | Out-Null "@ + # Save script to be able to call them from VBS file + if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) + { + New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force + } + # Save in UTF8 with BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + + # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + $CleanupTask = @" +' https://github.com/farag2/Sophia-Script-for-Windows +' https://t.me/sophia_chat + +CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 +"@ + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding utf8NoBOM -Force + # 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" + $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ @@ -12442,17 +12461,12 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show(`$ToastMessage) "@ - # Save script to be able to call them from VBS file - if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) - { - New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force - } # Save in UTF8 with BOM Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM -Force - # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up $ToastNotification = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat @@ -12479,12 +12493,18 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro } Register-ScheduledTask @Parameters -Force + # Start Task Scheduler in the end if any scheduled task was created $Script:ScheduledTasks = $true } "Delete" { # Remove files first unless we cannot remove folder if there's no more tasks there - Remove-Item -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Force -ErrorAction Ignore + $Paths = @( + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" + ) + Remove-Item -Path $Paths -Force -ErrorAction Ignore # Remove all old tasks # We have to use -ErrorAction Ignore in both cases, unless we get an error diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 84ea7f24..77c5365e 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -227,8 +227,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinCry = "$env:SystemRoot\TempCleaner.exe" # https://hone.gg Hone = "$env:LOCALAPPDATA\Programs\Hone\Hone.exe" - # https://github.com/ChrisTitusTech/winutil - winutil = "$env:TEMP\Winutil.log" # https://www.youtube.com/watch?v=5NBqbUUB1Pk WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas @@ -11499,11 +11497,14 @@ function CleanupTask New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force $CleanupTask = @" +# https://github.com/farag2/Sophia-Script-for-Windows +# https://t.me/sophia_chat + Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """$env:SystemRoot\System32\cleanmgr.exe""" -`$ProcessInfo.Arguments = """/sagerun:1337""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\cleanmgr.exe" +`$ProcessInfo.Arguments = "/sagerun:1337" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -11514,8 +11515,8 @@ Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force Start-Sleep -Seconds 3 `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """`$env:SystemRoot\System32\Dism.exe""" -`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\Dism.exe" +`$ProcessInfo.Arguments = "/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -11524,10 +11525,28 @@ Start-Sleep -Seconds 3 `$Process.Start() | Out-Null "@ + # Save script to be able to call them from VBS file + if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) + { + New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force + } + # Save in UTF8 with BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + + # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + $CleanupTask = @" +' https://github.com/farag2/Sophia-Script-for-Windows +' https://t.me/sophia_chat + +CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 +"@ + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + # 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" + $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ @@ -11661,17 +11680,12 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show(`$ToastMessage) "@ - # Save script to be able to call them from VBS file - if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) - { - New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force - } # Save in UTF8 with BOM Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force - # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up $ToastNotification = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat @@ -11698,12 +11712,18 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro } Register-ScheduledTask @Parameters -Force + # Start Task Scheduler in the end if any scheduled task was created $Script:ScheduledTasks = $true } "Delete" { # Remove files first unless we cannot remove folder if there's no more tasks there - Remove-Item -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Force -ErrorAction Ignore + $Paths = @( + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" + ) + Remove-Item -Path $Paths -Force -ErrorAction Ignore # Remove all old tasks # We have to use -ErrorAction Ignore in both cases, unless we get an error @@ -13090,7 +13110,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS) })] [string] @@ -13098,7 +13118,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS) })] [string] 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 a2d61be6..7cb8465c 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 @@ -226,8 +226,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinCry = "$env:SystemRoot\TempCleaner.exe" # https://hone.gg Hone = "$env:LOCALAPPDATA\Programs\Hone\Hone.exe" - # https://github.com/ChrisTitusTech/winutil - winutil = "$env:TEMP\Winutil.log" # https://www.youtube.com/watch?v=5NBqbUUB1Pk WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas @@ -11515,11 +11513,14 @@ function CleanupTask New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia\'' -TaskName ''Windows Cleanup''}"' -Force $CleanupTask = @" +# https://github.com/farag2/Sophia-Script-for-Windows +# https://t.me/sophia_chat + Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """$env:SystemRoot\System32\cleanmgr.exe""" -`$ProcessInfo.Arguments = """/sagerun:1337""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\cleanmgr.exe" +`$ProcessInfo.Arguments = "/sagerun:1337" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -11530,8 +11531,8 @@ Get-Process -Name cleanmgr, Dism, DismHost | Stop-Process -Force Start-Sleep -Seconds 3 `$ProcessInfo = New-Object -TypeName System.Diagnostics.ProcessStartInfo -`$ProcessInfo.FileName = """`$env:SystemRoot\System32\Dism.exe""" -`$ProcessInfo.Arguments = """/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart""" +`$ProcessInfo.FileName = "`$env:SystemRoot\System32\Dism.exe" +`$ProcessInfo.Arguments = "/Online /English /Cleanup-Image /StartComponentCleanup /NoRestart" `$ProcessInfo.UseShellExecute = `$true `$ProcessInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized @@ -11540,10 +11541,28 @@ Start-Sleep -Seconds 3 `$Process.Start() | Out-Null "@ + # Save script to be able to call them from VBS file + if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) + { + New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force + } + # Save in UTF8 with BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + + # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + $CleanupTask = @" +' https://github.com/farag2/Sophia-Script-for-Windows +' https://t.me/sophia_chat + +CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 +"@ + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding utf8NoBOM -Force + # 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" + $Action = New-ScheduledTaskAction -Execute wscript.exe -Argument "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest $Parameters = @{ @@ -11677,17 +11696,12 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show(`$ToastMessage) "@ - # Save script to be able to call them from VBS file - if (-not (Test-Path -Path $env:SystemRoot\System32\Tasks\Sophia)) - { - New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force - } # Save in UTF8 with BOM Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM -Force - # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up + # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up $ToastNotification = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat @@ -11714,12 +11728,18 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro } Register-ScheduledTask @Parameters -Force + # Start Task Scheduler in the end if any scheduled task was created $Script:ScheduledTasks = $true } "Delete" { # Remove files first unless we cannot remove folder if there's no more tasks there - Remove-Item -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Force -ErrorAction Ignore + $Paths = @( + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", + "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" + ) + Remove-Item -Path $Paths -Force -ErrorAction Ignore # Remove all old tasks # We have to use -ErrorAction Ignore in both cases, unless we get an error @@ -13106,7 +13126,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $SecondaryDNS) })] [string] @@ -13114,7 +13134,7 @@ function DNSoverHTTPS [Parameter(Mandatory = $false)] [ValidateScript({ - # isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS + # Isolate IPv4 IP addresses and check if $PrimaryDNS is not equal to $SecondaryDNS ((@((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object -FilterScript {($_ -as [IPAddress]).AddressFamily -ne "InterNetworkV6"}) -contains $_) -and ($_ -ne $PrimaryDNS) })] [string]