diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 132f3a4b..aa852397 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -11283,7 +11283,7 @@ function CleanupTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11323,6 +11323,34 @@ function CleanupTask New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force + + # Start the "Windows Cleanup" task if the "Run" button clicked + 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 = @" Get-Process -Name cleanmgr | Stop-Process -Force Get-Process -Name Dism | Stop-Process -Force @@ -11405,25 +11433,6 @@ while (`$true) } Register-ScheduledTask @Parameters -Force - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) - { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force - } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - - # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force - - # Start the "Windows Cleanup" task if the "Run" button clicked - 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 - $ToastNotification = @" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -11463,7 +11472,7 @@ while (`$true) `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Windows Cleanup Notification" task @@ -11486,7 +11495,8 @@ while (`$true) { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11504,8 +11514,9 @@ while (`$true) Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process { Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore } - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -Force -ErrorAction Ignore Remove-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Recurse -Force -ErrorAction Ignore + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore # Remove folder in Task Scheduler if there is no tasks left there if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia") @@ -11566,7 +11577,8 @@ function SoftwareDistributionTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11578,12 +11590,21 @@ function SoftwareDistributionTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force $SoftwareDistributionTask = @" (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') @@ -11612,7 +11633,7 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "SoftwareDistribution" task @@ -11633,9 +11654,13 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11709,7 +11734,8 @@ function TempTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11721,6 +11747,22 @@ function TempTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + $TempTask = @" Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Recurse -Force @@ -11747,7 +11789,7 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Temp" task @@ -11768,9 +11810,13 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -13778,6 +13824,22 @@ public static void PostMessage() Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.RestartWarning + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -13806,7 +13868,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Telegram channel [xml]$ToastTemplate = @" @@ -13833,7 +13895,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Discord group [xml]$ToastTemplate = @" @@ -13860,7 +13922,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt")) { 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 6c20ce4f..e669239e 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 @@ -7915,7 +7915,7 @@ function CleanupTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -7955,6 +7955,34 @@ function CleanupTask New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force + + # Start the "Windows Cleanup" task if the "Run" button clicked + 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 = @" Get-Process -Name cleanmgr | Stop-Process -Force Get-Process -Name Dism | Stop-Process -Force @@ -8037,25 +8065,6 @@ while (`$true) } Register-ScheduledTask @Parameters -Force - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) - { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force - } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - - # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force - - # Start the "Windows Cleanup" task if the "Run" button clicked - 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 - $ToastNotification = @" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -8095,7 +8104,7 @@ while (`$true) `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Windows Cleanup Notification" task @@ -8118,7 +8127,8 @@ while (`$true) { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -8136,8 +8146,9 @@ while (`$true) Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process { Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore } - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -Force -ErrorAction Ignore Remove-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Recurse -Force -ErrorAction Ignore + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore # Remove folder in Task Scheduler if there is no tasks left there if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia") @@ -8198,7 +8209,8 @@ function SoftwareDistributionTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -8210,12 +8222,21 @@ function SoftwareDistributionTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force $SoftwareDistributionTask = @" (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') @@ -8244,7 +8265,7 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "SoftwareDistribution" task @@ -8265,9 +8286,13 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -8341,7 +8366,8 @@ function TempTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -8353,6 +8379,22 @@ function TempTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + $TempTask = @" Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Recurse -Force @@ -8379,7 +8421,7 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Temp" task @@ -8400,9 +8442,13 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -10188,6 +10234,22 @@ public static void PostMessage() Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.RestartWarning + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -10216,7 +10278,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Telegram channel [xml]$ToastTemplate = @" @@ -10243,7 +10305,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Discord group [xml]$ToastTemplate = @" @@ -10270,7 +10332,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt")) { @@ -10286,6 +10348,16 @@ public static void PostMessage() gpupdate /force } + # [WinAPI.UpdateEnvironment]::Refresh() makes so that Meet Now icon returns even if was hid before, so we need to check which function was called previously + if ($Script:MeetNow) + { + MeetNow -Show + } + elseif ($Script:MeetNow -eq $false) + { + MeetNow -Hide + } + Remove-Item -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore Stop-Process -Name explorer -Force 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 15a0b731..abc05275 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 @@ -9082,7 +9082,7 @@ function CleanupTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -9122,6 +9122,34 @@ function CleanupTask New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force + + # Start the "Windows Cleanup" task if the "Run" button clicked + 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 = @" Get-Process -Name cleanmgr | Stop-Process -Force Get-Process -Name Dism | Stop-Process -Force @@ -9204,25 +9232,6 @@ while (`$true) } Register-ScheduledTask @Parameters -Force - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) - { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force - } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - - # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force - - # Start the "Windows Cleanup" task if the "Run" button clicked - 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 - $ToastNotification = @" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -9262,7 +9271,7 @@ while (`$true) `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Windows Cleanup Notification" task @@ -9285,7 +9294,8 @@ while (`$true) { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -9303,8 +9313,9 @@ while (`$true) Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process { Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore } - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -Force -ErrorAction Ignore Remove-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Recurse -Force -ErrorAction Ignore + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore # Remove folder in Task Scheduler if there is no tasks left there if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia") @@ -9365,7 +9376,8 @@ function SoftwareDistributionTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -9377,12 +9389,21 @@ function SoftwareDistributionTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force $SoftwareDistributionTask = @" (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') @@ -9411,7 +9432,7 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "SoftwareDistribution" task @@ -9432,9 +9453,13 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -9508,7 +9533,8 @@ function TempTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -9520,6 +9546,22 @@ function TempTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + $TempTask = @" Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Recurse -Force @@ -9546,7 +9588,7 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Temp" task @@ -9567,9 +9609,13 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11409,6 +11455,22 @@ public static void PostMessage() Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.RestartWarning + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -11437,7 +11499,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Telegram channel [xml]$ToastTemplate = @" @@ -11464,7 +11526,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Discord group [xml]$ToastTemplate = @" @@ -11491,7 +11553,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt")) { @@ -11507,6 +11569,16 @@ public static void PostMessage() gpupdate /force } + # [WinAPI.UpdateEnvironment]::Refresh() makes so that Meet Now icon returns even if was hid before, so we need to check which function was called previously + if ($Script:MeetNow) + { + MeetNow -Show + } + elseif ($Script:MeetNow -eq $false) + { + MeetNow -Hide + } + Remove-Item -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore Stop-Process -Name explorer -Force 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 4423f06a..58685b90 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Functions.ps1 @@ -55,7 +55,14 @@ $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 v5.14.3 (PowerShell 7 Remove-Module -Name Sophia -Force -ErrorAction Ignore Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force -Import-LocalizedData -BindingVariable Global:Localization -FileName Sophia -BaseDirectory $PSScriptRoot\Localizations +try +{ + Import-LocalizedData -BindingVariable Global:Localization -UICulture $PSUICulture -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia -ErrorAction Stop +} +catch +{ + Import-LocalizedData -BindingVariable Global:Localization -UICulture en-US -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia +} # The mandatory checks. Please, do not comment out this function Checks 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 8c848923..fb73e78f 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 @@ -11321,7 +11321,7 @@ function CleanupTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11361,6 +11361,34 @@ function CleanupTask New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force + + # Start the "Windows Cleanup" task if the "Run" button clicked + 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 = @" Get-Process -Name cleanmgr | Stop-Process -Force Get-Process -Name Dism | Stop-Process -Force @@ -11443,25 +11471,6 @@ while (`$true) } Register-ScheduledTask @Parameters -Force - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) - { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force - } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - - # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force - - # Start the "Windows Cleanup" task if the "Run" button clicked - 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 - $ToastNotification = @" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -11501,7 +11510,7 @@ while (`$true) `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Windows Cleanup Notification" task @@ -11524,7 +11533,8 @@ while (`$true) { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11542,8 +11552,9 @@ while (`$true) Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process { Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore } - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -Force -ErrorAction Ignore Remove-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Recurse -Force -ErrorAction Ignore + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore # Remove folder in Task Scheduler if there is no tasks left there if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia") @@ -11604,7 +11615,8 @@ function SoftwareDistributionTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11616,12 +11628,21 @@ function SoftwareDistributionTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force $SoftwareDistributionTask = @" (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') @@ -11650,7 +11671,7 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "SoftwareDistribution" task @@ -11671,9 +11692,13 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11747,7 +11772,8 @@ function TempTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11759,6 +11785,22 @@ function TempTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + $TempTask = @" Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Recurse -Force @@ -11785,7 +11827,7 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Temp" task @@ -11806,9 +11848,13 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -13818,16 +13864,24 @@ public static void PostMessage() Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.RestartWarning - <# - .NOTES - Load the WinRT.Runtime.dll and Microsoft.Windows.SDK.NET.dll assemblies in the current session in order to get localized UWP apps names + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - .LINK - https://github.com/microsoft/CsWinRT - https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref - #> - Add-Type -AssemblyName "$PSScriptRoot\..\bin\WinRT.Runtime.dll" - Add-Type -AssemblyName "$PSScriptRoot\..\bin\Microsoft.Windows.SDK.NET.dll" + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null + [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null # Telegram group [xml]$ToastTemplate = @" @@ -13854,7 +13908,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Telegram channel [xml]$ToastTemplate = @" @@ -13881,7 +13935,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Discord group [xml]$ToastTemplate = @" @@ -13908,7 +13962,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt")) { diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 06c40878..5470f949 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -5710,7 +5710,7 @@ function LatestInstalled.NET .NOTES Current user #> -function NetworkAdaptersSavePower +function NetworkAdaptersSavePower ### { param ( @@ -10689,7 +10689,7 @@ function CleanupTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -10729,6 +10729,34 @@ function CleanupTask New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force + + # Start the "Windows Cleanup" task if the "Run" button clicked + 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 = @" Get-Process -Name cleanmgr | Stop-Process -Force Get-Process -Name Dism | Stop-Process -Force @@ -10811,25 +10839,6 @@ while (`$true) } Register-ScheduledTask @Parameters -Force - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) - { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force - } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - - # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force - - # Start the "Windows Cleanup" task if the "Run" button clicked - 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 - $ToastNotification = @" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -10869,7 +10878,7 @@ while (`$true) `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Windows Cleanup Notification" task @@ -10892,7 +10901,8 @@ while (`$true) { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -10910,8 +10920,9 @@ while (`$true) Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process { Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore } - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -Force -ErrorAction Ignore Remove-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Recurse -Force -ErrorAction Ignore + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore # Remove folder in Task Scheduler if there is no tasks left there if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia") @@ -10972,7 +10983,8 @@ function SoftwareDistributionTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -10984,12 +10996,21 @@ function SoftwareDistributionTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force $SoftwareDistributionTask = @" (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') @@ -11018,7 +11039,7 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "SoftwareDistribution" task @@ -11039,9 +11060,13 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11115,7 +11140,8 @@ function TempTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11127,6 +11153,22 @@ function TempTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + $TempTask = @" Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Recurse -Force @@ -11153,7 +11195,7 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Temp" task @@ -11174,9 +11216,13 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -13180,14 +13226,24 @@ public static void PostMessage() } } - if ($Script:RegionChanged) + Write-Information -MessageData "" -InformationAction Continue + Write-Warning -Message $Localization.RestartWarning + + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) { - # Set the original region ID - Set-WinHomeLocation -GeoId $Script:Region + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - Write-Information -MessageData "" -InformationAction Continue - Write-Warning -Message $Localization.RestartWarning + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -13217,7 +13273,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Telegram channel [xml]$ToastTemplate = @" @@ -13244,7 +13300,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Discord group [xml]$ToastTemplate = @" @@ -13271,7 +13327,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt")) { @@ -13287,6 +13343,16 @@ public static void PostMessage() gpupdate /force } + # [WinAPI.UpdateEnvironment]::Refresh() makes so that Meet Now icon returns even if was hid before, so we need to check which function was called previously + if ($Script:MeetNow) + { + MeetNow -Show + } + elseif ($Script:MeetNow -eq $false) + { + MeetNow -Hide + } + Remove-Item -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore Stop-Process -Name explorer -Force 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 ce4eb562..028f6323 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Functions.ps1 @@ -55,7 +55,14 @@ $Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.2.3 | Made with $( Remove-Module -Name Sophia -Force -ErrorAction Ignore Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force -Import-LocalizedData -BindingVariable Global:Localization -FileName Sophia -BaseDirectory $PSScriptRoot\Localizations +try +{ + Import-LocalizedData -BindingVariable Global:Localization -UICulture $PSUICulture -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia -ErrorAction Stop +} +catch +{ + Import-LocalizedData -BindingVariable Global:Localization -UICulture en-US -BaseDirectory $PSScriptRoot\Localizations -FileName Sophia +} # The mandatory checks. Please, do not comment out this function Checks 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 b5596e11..f0bd45ff 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 @@ -10727,7 +10727,7 @@ function CleanupTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -10767,6 +10767,34 @@ function CleanupTask New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$VolumeCache" -Name StateFlags1337 -PropertyType DWord -Value 2 -Force } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force + + # Start the "Windows Cleanup" task if the "Run" button clicked + 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 = @" Get-Process -Name cleanmgr | Stop-Process -Force Get-Process -Name Dism | Stop-Process -Force @@ -10849,25 +10877,6 @@ while (`$true) } Register-ScheduledTask @Parameters -Force - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) - { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force - } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - - # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command)) - { - New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force - } - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -PropertyType String -Value "" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force - - # Start the "Windows Cleanup" task if the "Run" button clicked - 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 - $ToastNotification = @" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null @@ -10907,7 +10916,7 @@ while (`$true) `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Windows Cleanup Notification" task @@ -10930,7 +10939,8 @@ while (`$true) { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -10948,8 +10958,9 @@ while (`$true) Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches | ForEach-Object -Process { Remove-ItemProperty -Path $_.PsPath -Name StateFlags1337 -Force -ErrorAction Ignore } - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -Force -ErrorAction Ignore Remove-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Recurse -Force -ErrorAction Ignore + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore # Remove folder in Task Scheduler if there is no tasks left there if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia") @@ -11010,7 +11021,8 @@ function SoftwareDistributionTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11022,12 +11034,21 @@ function SoftwareDistributionTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } - # Persist the Settings notifications to prevent to immediately disappear from Action Center - if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel")) + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) { - New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Force + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force } - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force $SoftwareDistributionTask = @" (Get-Service -Name wuauserv).WaitForStatus('Stopped', '01:00:00') @@ -11056,7 +11077,7 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "SoftwareDistribution" task @@ -11077,9 +11098,13 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11153,7 +11178,8 @@ function TempTask { # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folders in Task Scheduler. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -11165,6 +11191,22 @@ function TempTask $ScheduleService.GetFolder("\").DeleteFolder("SophiApp", $null) } + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force + + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + $TempTask = @" Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_.CreationTime -lt (Get-Date).AddDays(-1)} | Remove-Item -Recurse -Force @@ -11191,7 +11233,7 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ `$ToastXml.LoadXml(`$ToastTemplate.OuterXml) `$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New(`$ToastXML) -[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel""").Show(`$ToastMessage) +[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("""Sophia""").Show(`$ToastMessage) "@ # Create the "Temp" task @@ -11212,9 +11254,13 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ } "Delete" { + Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Recurse -Force -ErrorAction Ignore + Remove-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force -ErrorAction Ignore + # Remove all old tasks Unregister-ScheduledTask -TaskPath "\Sophia Script\", "\SophiApp\" -TaskName "Windows Cleanup", "Windows Cleanup Notification", SoftwareDistribution, Temp -Confirm:$false -ErrorAction Ignore - # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folder do not exist + + # Remove folder in Task Scheduler if there is no tasks left there. We cannot remove all old folders explicitly and not get errors if any of folders do not exist $ScheduleService = New-Object -ComObject Schedule.Service $ScheduleService.Connect() if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Sophia Script") @@ -13217,25 +13263,27 @@ public static void PostMessage() } } - if ($Script:RegionChanged) - { - # Set the original region ID - Set-WinHomeLocation -GeoId $Script:Region - } - Write-Information -MessageData "" -InformationAction Continue Write-Warning -Message $Localization.RestartWarning - <# - .NOTES - Load the WinRT.Runtime.dll and Microsoft.Windows.SDK.NET.dll assemblies in the current session in order to get localized UWP apps names + # Persist Sophia notifications to prevent to immediately disappear from Action Center + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Force + } + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings\Sophia -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force - .LINK - https://github.com/microsoft/CsWinRT - https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref - #> - Add-Type -AssemblyName "$PSScriptRoot\..\bin\WinRT.Runtime.dll" - Add-Type -AssemblyName "$PSScriptRoot\..\bin\Microsoft.Windows.SDK.NET.dll" + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Force + } + # Register app + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name DisplayName -Value Sophia -PropertyType String -Force + # Determines whether the app can be seen in Settings where the user can turn notifications on or off + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\AppUserModelId\Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force + + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null + [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null # Telegram group [xml]$ToastTemplate = @" @@ -13262,7 +13310,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Telegram channel [xml]$ToastTemplate = @" @@ -13289,7 +13337,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) # Discord group [xml]$ToastTemplate = @" @@ -13316,7 +13364,7 @@ public static void PostMessage() $ToastXml.LoadXml($ToastTemplate.OuterXml) $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML) - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel").Show($ToastMessage) + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sophia").Show($ToastMessage) if ((Test-Path -Path "$env:TEMP\Computer.txt") -or (Test-Path -Path "$env:TEMP\User.txt")) { @@ -13332,6 +13380,16 @@ public static void PostMessage() gpupdate /force } + # [WinAPI.UpdateEnvironment]::Refresh() makes so that Meet Now icon returns even if was hid before, so we need to check which function was called previously + if ($Script:MeetNow) + { + MeetNow -Show + } + elseif ($Script:MeetNow -eq $false) + { + MeetNow -Hide + } + Remove-Item -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore Stop-Process -Name explorer -Force