From a6e0064daf44546212836efb15382ffd8d727417 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 14 Jul 2024 21:06:09 +0300 Subject: [PATCH] Minor improvements --- .../Module/Sophia.psm1 | 25 +++++++---------- .../Module/Sophia.psm1 | 4 +-- .../Module/Sophia.psm1 | 4 +-- .../Module/Sophia.psm1 | 27 +++++++------------ .../Module/Sophia.psm1 | 17 +++++------- .../Module/Sophia.psm1 | 17 +++++------- 6 files changed, 33 insertions(+), 61 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 71aeb01f..1c043f01 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -282,11 +282,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether Windows was broken by 3rd party harmful tweakers and trojans $Tweakers = @{ # https://forum.ru-board.com/topic.cgi?forum=62&topic=30617&start=1600#14 - AutoSettingsPS = "$(Get-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" + AutoSettingsPS = "$(Get-WinEvent -LogName `"Windows PowerShell`" | Where-Object -FilterScript {($_.Id -eq 800) -and ($_.Message -match `"AutoSettingsPS`")} | Select-Object -First 1)" # Flibustier custom Windows image Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" - # https://github.com/hellzerg/optimizer - Optimizer = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"optimizer`"})" # https://github.com/builtbybel/Winpilot Winpilot = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Winpilot`"})" # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 @@ -3969,31 +3967,26 @@ function UnpinTaskbarShortcuts $Shell = (New-Object -ComObject Shell.Application).NameSpace("$env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar") $Shortcut = $Shell.ParseName("Microsoft Edge.lnk") # Extract the localized "Unpin from taskbar" string from shell32.dll - $Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq "$([WinAPI.GetStrings]::GetString(5387))"} | ForEach-Object -Process {$_.DoIt()} + $Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } Store { - # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names if ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {$_.Name -eq "Microsoft Store"}) { - Start-Job -ScriptBlock { - # Extract the localized "Unpin from taskbar" string from shell32.dll - ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { - $_.Name -eq "Microsoft Store" - }).Verbs() | Where-Object -FilterScript {$_.Name -eq $using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} - } | Receive-Job -Wait -AutoRemoveJob + # Extract the localized "Unpin from taskbar" string from shell32.dll + ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { + $_.Name -eq "Microsoft Store" + }).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } Mail { - # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names if (Get-AppxPackage -Name microsoft.windowscommunicationsapps) { - Start-Job -ScriptBlock { - $Apps = (New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() - ($Apps | Where-Object -FilterScript {$_.Path -eq "microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail"}).Verbs() | Where-Object -FilterScript {$_.Name -eq $using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} - } | Receive-Job -Wait -AutoRemoveJob + ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { + $_.Path -match "microsoft.windowscommunicationsapp" + }).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } } 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 1ef1f665..a5b3ff7b 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 @@ -282,11 +282,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether Windows was broken by 3rd party harmful tweakers and trojans $Tweakers = @{ # https://forum.ru-board.com/topic.cgi?forum=62&topic=30617&start=1600#14 - AutoSettingsPS = "$(Get-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" + AutoSettingsPS = "$(Get-WinEvent -LogName `"Windows PowerShell`" | Where-Object -FilterScript {($_.Id -eq 800) -and ($_.Message -match `"AutoSettingsPS`")} | Select-Object -First 1)" # Flibustier custom Windows image Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" - # https://github.com/hellzerg/optimizer - Optimizer = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"optimizer`"})" # https://github.com/builtbybel/Winpilot Winpilot = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Winpilot`"})" # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 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 2fadd10e..0b0d75b8 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 @@ -282,11 +282,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether Windows was broken by 3rd party harmful tweakers and trojans $Tweakers = @{ # https://forum.ru-board.com/topic.cgi?forum=62&topic=30617&start=1600#14 - AutoSettingsPS = "$(Get-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" + AutoSettingsPS = "$(Get-WinEvent -LogName `"Windows PowerShell`" | Where-Object -FilterScript {($_.Id -eq 800) -and ($_.Message -match `"AutoSettingsPS`")} | Select-Object -First 1)" # Flibustier custom Windows image Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" - # https://github.com/hellzerg/optimizer - Optimizer = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"optimizer`"})" # https://github.com/builtbybel/Winpilot Winpilot = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Winpilot`"})" # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 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 c2075254..9e06510e 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 @@ -281,11 +281,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether Windows was broken by 3rd party harmful tweakers and trojans $Tweakers = @{ # https://forum.ru-board.com/topic.cgi?forum=62&topic=30617&start=1600#14 - AutoSettingsPS = "$(Get-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" + AutoSettingsPS = "$(Get-WinEvent -LogName `"Windows PowerShell`" | Where-Object -FilterScript {($_.Id -eq 800) -and ($_.Message -match `"AutoSettingsPS`")} | Select-Object -First 1)" # Flibustier custom Windows image Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" - # https://github.com/hellzerg/optimizer - Optimizer = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"optimizer`"})" # https://github.com/builtbybel/Winpilot Winpilot = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Winpilot`"})" # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 @@ -3978,26 +3976,21 @@ function UnpinTaskbarShortcuts } Store { - # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names if ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {$_.Name -eq "Microsoft Store"}) { - Start-Job -ScriptBlock { - # Extract the localized "Unpin from taskbar" string from shell32.dll - ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { - $_.Name -eq "Microsoft Store" - }).Verbs() | Where-Object -FilterScript {$_.Name -eq $using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} - } | Receive-Job -Wait -AutoRemoveJob + # Extract the localized "Unpin from taskbar" string from shell32.dll + ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { + $_.Name -eq "Microsoft Store" + }).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } Mail { - # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names if (Get-AppxPackage -Name microsoft.windowscommunicationsapps) { - Start-Job -ScriptBlock { - $Apps = (New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() - ($Apps | Where-Object -FilterScript {$_.Path -eq "microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail"}).Verbs() | Where-Object -FilterScript {$_.Name -eq $using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} - } | Receive-Job -Wait -AutoRemoveJob + ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { + $_.Path -match "microsoft.windowscommunicationsapp" + }).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } } @@ -11122,7 +11115,7 @@ function UninstallUWPApps $UncheckedAppxPackages = @( # Dolby Access "DolbyLaboratories.DolbyAccess", - + # Windows Media Player "Microsoft.ZuneMusic", @@ -11360,7 +11353,7 @@ function UninstallUWPApps } } - $PackagesIds = [Windows.Management.Deployment.PackageManager, Windows.Web, ContentType = WindowsRuntime]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName + $PackagesIds = [Windows.Management.Deployment.PackageManager]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName foreach ($AppxPackage in $AppxPackages) { $PackageId = $PackagesIds | Where-Object -FilterScript {$_.Name -eq $AppxPackage.Name} diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 4441a52b..87bb17a8 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -268,11 +268,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether Windows was broken by 3rd party harmful tweakers and trojans $Tweakers = @{ # https://forum.ru-board.com/topic.cgi?forum=62&topic=30617&start=1600#14 - AutoSettingsPS = "$(Get-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" + AutoSettingsPS = "$(Get-WinEvent -LogName `"Windows PowerShell`" | Where-Object -FilterScript {($_.Id -eq 800) -and ($_.Message -match `"AutoSettingsPS`")} | Select-Object -First 1)" # Flibustier custom Windows image Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" - # https://github.com/hellzerg/optimizer - Optimizer = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"optimizer`"})" # https://github.com/builtbybel/Winpilot Winpilot = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Winpilot`"})" # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 @@ -3697,20 +3695,17 @@ function UnpinTaskbarShortcuts $Shell = (New-Object -ComObject Shell.Application).NameSpace("$env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar") $Shortcut = $Shell.ParseName("Microsoft Edge.lnk") # Extract the localized "Unpin from taskbar" string from shell32.dll - $Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq "$([WinAPI.GetStrings]::GetString(5387))"} | ForEach-Object -Process {$_.DoIt()} + $Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } Store { - # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names if ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {$_.Name -eq "Microsoft Store"}) { - Start-Job -ScriptBlock { - # Extract the localized "Unpin from taskbar" string from shell32.dll - ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { - $_.Name -eq "Microsoft Store" - }).Verbs() | Where-Object -FilterScript {$_.Name -eq $using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} - } | Receive-Job -Wait -AutoRemoveJob + # Extract the localized "Unpin from taskbar" string from shell32.dll + ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { + $_.Name -eq "Microsoft Store" + }).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } } 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 6290263c..b60ca67e 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 @@ -267,11 +267,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); # Check whether Windows was broken by 3rd party harmful tweakers and trojans $Tweakers = @{ # https://forum.ru-board.com/topic.cgi?forum=62&topic=30617&start=1600#14 - AutoSettingsPS = "$(Get-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" + AutoSettingsPS = "$(Get-WinEvent -LogName `"Windows PowerShell`" | Where-Object -FilterScript {($_.Id -eq 800) -and ($_.Message -match `"AutoSettingsPS`")} | Select-Object -First 1)" # Flibustier custom Windows image Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" - # https://github.com/hellzerg/optimizer - Optimizer = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"optimizer`"})" # https://github.com/builtbybel/Winpilot Winpilot = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Winpilot`"})" # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 @@ -3715,20 +3713,17 @@ function UnpinTaskbarShortcuts $Shell = (New-Object -ComObject Shell.Application).NameSpace("$env:AppData\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar") $Shortcut = $Shell.ParseName("Microsoft Edge.lnk") # Extract the localized "Unpin from taskbar" string from shell32.dll - $Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq "$([WinAPI.GetStrings]::GetString(5387))"} | ForEach-Object -Process {$_.DoIt()} + $Shortcut.Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } Store { - # Start-Job is used due to that the calling this function before UninstallUWPApps breaks the retrieval of the localized UWP apps packages names if ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript {$_.Name -eq "Microsoft Store"}) { - Start-Job -ScriptBlock { - # Extract the localized "Unpin from taskbar" string from shell32.dll - ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { - $_.Name -eq "Microsoft Store" - }).Verbs() | Where-Object -FilterScript {$_.Name -eq $using:LocalizedString} | ForEach-Object -Process {$_.DoIt()} - } | Receive-Job -Wait -AutoRemoveJob + # Extract the localized "Unpin from taskbar" string from shell32.dll + ((New-Object -ComObject Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | Where-Object -FilterScript { + $_.Name -eq "Microsoft Store" + }).Verbs() | Where-Object -FilterScript {$_.Name -eq $LocalizedString} | ForEach-Object -Process {$_.DoIt()} } } }