From 2a3756c81f9f4b9d4c3ddf397f192afaad73b550 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Fri, 21 Jun 2024 13:16:28 +0300 Subject: [PATCH] Fixed WSL and OneDrive functions. Removed TempFolder & RestoreUWPApps functions --- README.md | 8 +- README_de-de.md | 8 +- README_uk-ua.md | 8 +- Wrapper/Config/config_Windows_10.json | 29 - Wrapper/Config/config_Windows_10_LTSC.json | 18 - Wrapper/Config/config_Windows_11.json | 29 - .../de-DE/tooltip_Windows_10.json | 24 - .../de-DE/tooltip_Windows_11.json | 24 - .../en-US/tooltip_Windows_10.json | 24 - .../en-US/tooltip_Windows_11.json | 24 - .../ru-RU/tooltip_Windows_10.json | 24 - .../ru-RU/tooltip_Windows_11.json | 24 - .../Module/Sophia.psm1 | 668 +---------------- src/Sophia_Script_for_Windows_10/Sophia.ps1 | 29 +- .../Module/Sophia.psm1 | 308 +------- .../Sophia.ps1 | 10 +- .../Module/Sophia.psm1 | 346 +-------- .../Sophia.ps1 | 10 +- .../Module/Sophia.psm1 | 686 +---------------- .../Sophia.ps1 | 29 +- .../Module/Sophia.psm1 | 684 ++--------------- src/Sophia_Script_for_Windows_11/Sophia.ps1 | 33 +- .../Module/Sophia.psm1 | 700 ++---------------- .../Sophia.ps1 | 29 +- 24 files changed, 241 insertions(+), 3535 deletions(-) diff --git a/README.md b/README.md index 80d89b36..743cba7a 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,12 @@

- - - - - - + [telegram-news-badge]: https://img.shields.io/badge/Sophia%20News-Telegram-blue?style=flat&logo=Telegram [telegram-news]: https://t.me/sophianews @@ -34,6 +29,7 @@ [discord-news-badge]: https://discordapp.com/api/guilds/1006179075263561779/widget.png?style=shield [discord-link]: https://discord.gg/sSryhaEv79 [![Discord][discord-news-badge]][discord-link] +

diff --git a/README_de-de.md b/README_de-de.md index 3a62a688..34d32235 100644 --- a/README_de-de.md +++ b/README_de-de.md @@ -11,17 +11,12 @@

- - - - - - + [telegram-news-badge]: https://img.shields.io/badge/Sophia%20News-Telegram-blue?style=flat&logo=Telegram [telegram-news]: https://t.me/sophianews @@ -34,6 +29,7 @@ [discord-news-badge]: https://discordapp.com/api/guilds/1006179075263561779/widget.png?style=shield [discord-link]: https://discord.gg/sSryhaEv79 [![Discord][discord-news-badge]][discord-link] +

diff --git a/README_uk-ua.md b/README_uk-ua.md index e4591a9b..dc48440e 100644 --- a/README_uk-ua.md +++ b/README_uk-ua.md @@ -11,17 +11,12 @@

- - - - - - + [telegram-news-badge]: https://img.shields.io/badge/Sophia%20News-Telegram-blue?style=flat&logo=Telegram [telegram-news]: https://t.me/sophianews @@ -34,6 +29,7 @@ [discord-news-badge]: https://discordapp.com/api/guilds/1006179075263561779/widget.png?style=shield [discord-link]: https://discord.gg/sSryhaEv79 [![Discord][discord-news-badge]][discord-link] +

diff --git a/Wrapper/Config/config_Windows_10.json b/Wrapper/Config/config_Windows_10.json index 4837e4f7..487ed023 100644 --- a/Wrapper/Config/config_Windows_10.json +++ b/Wrapper/Config/config_Windows_10.json @@ -1058,22 +1058,6 @@ "Preset": "Zero", "WindowsDefault": "One" }, - { - "Region": "System", - "Control": "cmb", - "Required": "false", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive" - }, - "One": { - "Tag": "Default" - } - }, - "Preset": "Zero", - "WindowsDefault": "One" - }, { "Region": "System", "Control": "cmb", @@ -1824,19 +1808,6 @@ "Preset": "", "WindowsDefault": "" }, - { - "Region": "UWP apps", - "Control": "chk", - "Required": "false", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "" - } - }, - "Preset": "", - "WindowsDefault": "" - }, { "Region": "UWP apps", "Control": "cmb", diff --git a/Wrapper/Config/config_Windows_10_LTSC.json b/Wrapper/Config/config_Windows_10_LTSC.json index 9e7209a2..f4b3b62e 100644 --- a/Wrapper/Config/config_Windows_10_LTSC.json +++ b/Wrapper/Config/config_Windows_10_LTSC.json @@ -932,24 +932,6 @@ "LTSC2019": "true", "LTSC2021": "true" }, - { - "Region": "System", - "Control": "cmb", - "Required": "false", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive" - }, - "One": { - "Tag": "Default" - } - }, - "Preset": "Zero", - "WindowsDefault": "One", - "LTSC2019": "true", - "LTSC2021": "true" - }, { "Region": "System", "Control": "cmb", diff --git a/Wrapper/Config/config_Windows_11.json b/Wrapper/Config/config_Windows_11.json index bb700c6f..16608a58 100644 --- a/Wrapper/Config/config_Windows_11.json +++ b/Wrapper/Config/config_Windows_11.json @@ -981,22 +981,6 @@ "Preset": "Zero", "WindowsDefault": "One" }, - { - "Region": "System", - "Control": "cmb", - "Required": "false", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive" - }, - "One": { - "Tag": "Default" - } - }, - "Preset": "Zero", - "WindowsDefault": "One" - }, { "Region": "System", "Control": "cmb", @@ -1705,19 +1689,6 @@ "Preset": "", "WindowsDefault": "" }, - { - "Region": "UWP apps", - "Control": "chk", - "Required": "false", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "" - } - }, - "Preset": "", - "WindowsDefault": "" - }, { "Region": "UWP apps", "Control": "cmb", diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_10.json b/Wrapper/Localizations/de-DE/tooltip_Windows_10.json index bc9a6e69..3005c460 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_10.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_10.json @@ -928,20 +928,6 @@ } } }, - { - "Region": "System", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive", - "ToolTip": "Setzt den Pfad der Umgebungsvariablen %TEMP% auf %SystemDrive%\\Temp." - }, - "One": { - "Tag": "Default", - "ToolTip": "Setzt den Pfad der Umgebungsvariablen %TEMP% auf %LOCALAPPDATA%\\Temp (Standardeinstellung)." - } - } - }, { "Region": "System", "Function": "Win32LongPathLimit", @@ -1604,16 +1590,6 @@ } } }, - { - "Region": "UWP apps", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "", - "ToolTip": "Standard-UWP-Apps mithilfe des Popup-Dialogfelds wieder herstellen. UWP-Apps können nur wiederhergestellt werden, wenn sie nur für den aktuellen Benutzer deinstalliert wurden." - } - } - }, { "Region": "UWP apps", "Function": "HEVC", diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json index 146c8fff..6e15474b 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json @@ -862,20 +862,6 @@ } } }, - { - "Region": "System", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive", - "ToolTip": "Setzt den Pfad der Umgebungsvariablen %TEMP% auf %SystemDrive%\\Temp." - }, - "One": { - "Tag": "Default", - "ToolTip": "Setzt den Pfad der Umgebungsvariablen %TEMP% auf %LOCALAPPDATA%\\Temp (Standardeinstellung)." - } - } - }, { "Region": "System", "Function": "Win32LongPathLimit", @@ -1503,16 +1489,6 @@ } } }, - { - "Region": "UWP apps", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "", - "ToolTip": "Standard-UWP-Apps mithilfe des Popup-Dialogfelds wieder herstellen. UWP-Apps können nur wiederhergestellt werden, wenn sie nur für den aktuellen Benutzer deinstalliert wurden." - } - } - }, { "Region": "UWP apps", "Function": "CortanaAutostart", diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_10.json b/Wrapper/Localizations/en-US/tooltip_Windows_10.json index 79d30c24..6e0a8c0f 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_10.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_10.json @@ -928,20 +928,6 @@ } } }, - { - "Region": "System", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive", - "ToolTip": "Change the %TEMP% environment variable path to %SystemDrive%\\Temp." - }, - "One": { - "Tag": "Default", - "ToolTip": "Change %TEMP% environment variable path to %LOCALAPPDATA%\\Temp (default value)." - } - } - }, { "Region": "System", "Function": "Win32LongPathLimit", @@ -1604,16 +1590,6 @@ } } }, - { - "Region": "UWP apps", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "", - "ToolTip": "Restore the default UWP apps using the pop-up dialog box. UWP apps can be restored only if they were uninstalled only for the current user." - } - } - }, { "Region": "UWP apps", "Function": "HEVC", diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_11.json b/Wrapper/Localizations/en-US/tooltip_Windows_11.json index 70ee781b..649ae90c 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_11.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_11.json @@ -862,20 +862,6 @@ } } }, - { - "Region": "System", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive", - "ToolTip": "Change the %TEMP% environment variable path to %SystemDrive%\\Temp." - }, - "One": { - "Tag": "Default", - "ToolTip": "Change %TEMP% environment variable path to %LOCALAPPDATA%\\Temp (default value)." - } - } - }, { "Region": "System", "Function": "Win32LongPathLimit", @@ -1503,16 +1489,6 @@ } } }, - { - "Region": "UWP apps", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "", - "ToolTip": "Restore the default UWP apps using the pop-up dialog box. UWP apps can be restored only if they were uninstalled only for the current user." - } - } - }, { "Region": "UWP apps", "Function": "CortanaAutostart", diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json index fa0b9fd2..a23659c5 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_10.json @@ -928,20 +928,6 @@ } } }, - { - "Region": "System", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive", - "ToolTip": "Изменить путь переменной среды для %TEMP% на %SystemDrive%\\Temp." - }, - "One": { - "Tag": "Default", - "ToolTip": "Изменить путь переменной среды для %TEMP% на %LOCALAPPDATA%\\Temp (значение по умолчанию)." - } - } - }, { "Region": "System", "Function": "Win32LongPathLimit", @@ -1604,16 +1590,6 @@ } } }, - { - "Region": "UWP apps", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "", - "ToolTip": "Восстановить стандартные UWP-приложения, используя всплывающее диалоговое окно. UWP-приложения могут быть восстановлены, только если они были удалены для текущего пользователя." - } - } - }, { "Region": "UWP apps", "Function": "HEVC", diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json index 91d36dba..248c4cfb 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json @@ -862,20 +862,6 @@ } } }, - { - "Region": "System", - "Function": "TempFolder", - "Arg": { - "Zero": { - "Tag": "SystemDrive", - "ToolTip": "Изменить путь переменной среды для %TEMP% на %SystemDrive%\\Temp." - }, - "One": { - "Tag": "Default", - "ToolTip": "Изменить путь переменной среды для %TEMP% на %LOCALAPPDATA%\\Temp (значение по умолчанию)." - } - } - }, { "Region": "System", "Function": "Win32LongPathLimit", @@ -1503,16 +1489,6 @@ } } }, - { - "Region": "UWP apps", - "Function": "RestoreUWPApps", - "Arg": { - "Zero": { - "Tag": "", - "ToolTip": "Восстановить стандартные UWP-приложения, используя всплывающее диалоговое окно. UWP-приложения могут быть восстановлены, только если они были удалены для текущего пользователя." - } - } - }, { "Region": "UWP apps", "Function": "CortanaAutostart", diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 5973fe16..1ce3bfc0 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -225,8 +225,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); "Ghost Toolbox" = "$env:SystemRoot\System32\migwiz\dlmanifests\run.ghost.cmd" # https://win10tweaker.ru "Win 10 Tweaker" = "HKCU:\Software\Win 10 Tweaker" - # https://forum.ru-board.com/topic.cgi?forum=5&topic=50519 - "Modern Tweaker" = "Registry::HKEY_CLASSES_ROOT\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\shell\Modern Cleaner" # https://boosterx.ru BoosterX = "$env:ProgramFiles\GameModeX\GameModeX.exe" # https://forum.ru-board.com/topic.cgi?forum=5&topic=14285&start=400#11 @@ -247,6 +245,8 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); WinClean = "$env:ProgramFiles\WinClean Plus Apps" # https://github.com/Atlas-OS/Atlas AtlasOS = "$env:SystemRoot\AtlasModules" + # https://www.gearupbooster.com + "GearUP Booster" = "${env:ProgramFiles(x86)}\GearUPBooster" } foreach ($Tweaker in $Tweakers.Keys) { @@ -280,13 +280,15 @@ 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-Item -Path `"HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`" | Where-Object -FilterScript {$_.Property -match `"AutoSettingsPS`"})" # Flibustier custom Windows image - Flibustier = "$(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\.NETFramework\Performance -Name *flibustier)" + 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`"})" + 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`"})" + 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 + "Modern Tweaker" = "$((Get-ItemProperty -Path `"HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache`").PSObject.Properties | Where-Object -FilterScript {$_.Value -eq `"Modern Tweaker`"})" } foreach ($Tweaker in $Tweakers.Keys) { @@ -1920,7 +1922,7 @@ function AdvertisingID ) # Remove all policies in order to make changes visible in UI only if it's possible - Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo -Name DisabledByGroupPolicy -Force -ErrorAction Ignore + Remove-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo -Name DisabledByGroupPolicy -Force -ErrorAction Ignore Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name DisabledByGroupPolicy -Type CLEAR switch ($PSCmdlet.ParameterSetName) @@ -5121,10 +5123,6 @@ function OneDrive [switch] $Install, - [Parameter( - Mandatory = $true, - ParameterSetName = "Install" - )] [switch] $AllUsers ) @@ -5294,11 +5292,11 @@ public static bool MarkFileDelete (string sourcefile) if ($AllUsers) { # Install OneDrive for all users - Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe -ArgumentList "/allusers" -Wait + Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe -ArgumentList "/allusers" } else { - Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe -Wait + Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe } } else @@ -5333,7 +5331,7 @@ public static bool MarkFileDelete (string sourcefile) # Remove invalid chars [xml]$OneDriveXML = $Content -replace "", "" - $OneDriveURL = ($OneDriveXML).root.update.amd64binary.url | Select-Object -Index 1 + $OneDriveURL = $OneDriveXML.root.update.amd64binary.url | Select-Object -Index 1 $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $Parameters = @{ Uri = $OneDriveURL @@ -5346,7 +5344,7 @@ public static bool MarkFileDelete (string sourcefile) if ($AllUsers) { # Install OneDrive for all users to %ProgramFiles% - Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe -ArgumentList "/allusers" -Wait + Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe -ArgumentList "/allusers" } else { @@ -5605,296 +5603,6 @@ function Hibernation } } -<# - .SYNOPSIS - The %TEMP% environment variable path - - .PARAMETER SystemDrive - Change the %TEMP% environment variable path to %SystemDrive%\Temp - - .PARAMETER Default - Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp - - .EXAMPLE - TempFolder -SystemDrive - - .EXAMPLE - TempFolder -Default - - .NOTES - Machine-wide -#> -function TempFolder -{ - param - ( - [Parameter( - Mandatory = $true, - ParameterSetName = "SystemDrive" - )] - [switch] - $SystemDrive, - - [Parameter( - Mandatory = $true, - ParameterSetName = "Default" - )] - [switch] - $Default - ) - - switch ($PSCmdlet.ParameterSetName) - { - "SystemDrive" - { - if ((Get-LocalUser | Where-Object -FilterScript {$_.Enabled}).Count -gt 1) - { - Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message $Localization.Skipped -Verbose - - return - } - - # PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word - # https://github.com/PowerShell/PowerShell/issues/21070 - if ((Get-Item -Path $env:TEMP).FullName -eq "$env:SystemDrive\Temp") - { - Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message $Localization.Skipped -Verbose - - return - } - - # Restart the Printer Spooler service (Spooler) - Restart-Service -Name Spooler -Force - - # Stop OneDrive processes - Stop-Process -Name OneDrive, FileCoAuth -Force -ErrorAction Ignore - - if (-not (Test-Path -Path $env:SystemDrive\Temp)) - { - New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force - } - - # Cleaning up folders - Remove-Item -Path $env:SystemRoot\Temp -Recurse -Force -ErrorAction Ignore - Get-Item -Path $env:TEMP -Force | Where-Object -FilterScript {$_.LinkType -ne "SymbolicLink"} | Remove-Item -Recurse -Force -ErrorAction Ignore - - if (-not (Test-Path -Path $env:LOCALAPPDATA\Temp)) - { - New-Item -Path $env:LOCALAPPDATA\Temp -ItemType Directory -Force - } - - # If there are some files or folders left in %LOCALAPPDATA\Temp% - if ((Get-ChildItem -Path $env:TEMP -Force -ErrorAction Ignore | Measure-Object).Count -ne 0) - { - # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa - # The system does not move the file until the operating system is restarted - # The system moves the file immediately after AUTOCHK is executed, but before creating any paging files - $Signature = @{ - Namespace = "WinAPI" - Name = "DeleteFiles" - Language = "CSharp" - CompilerParameters = $CompilerParameters - MemberDefinition = @" -public enum MoveFileFlags -{ - MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 -} - -[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] -static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags); - -public static bool MarkFileDelete (string sourcefile) -{ - return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); -} -"@ - } - - if (-not ("WinAPI.DeleteFiles" -as [type])) - { - Add-Type @Signature - } - - try - { - Get-ChildItem -Path $env:TEMP -Recurse -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Stop - } - catch - { - # If files are in use remove them at the next boot - Get-ChildItem -Path $env:TEMP -Recurse -Force -ErrorAction Ignore | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)} - } - - $SymbolicLinkTask = @" -Get-ChildItem -Path `$env:LOCALAPPDATA\Temp -Recurse -Force | Remove-Item -Recurse -Force - -Get-Item -Path `$env:LOCALAPPDATA\Temp -Force | Where-Object -FilterScript {`$_.LinkType -ne """SymbolicLink"""} | Remove-Item -Recurse -Force -New-Item -Path `$env:LOCALAPPDATA\Temp -ItemType SymbolicLink -Value `$env:SystemDrive\Temp -Force - -Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false -"@ - - # Create a temporary scheduled task to create a symbolic link to the %SystemDrive%\Temp folder - # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method - # https://github.com/PowerShell/PowerShell/issues/21377 - $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $SymbolicLinkTask" - $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest - $Parameters = @{ - TaskName = "SymbolicLink" - Principal = $Principal - Action = $Action - Settings = $Settings - Trigger = $Trigger - } - Register-ScheduledTask @Parameters -Force - } - else - { - # Create a symbolic link to the %SystemDrive%\Temp folder - New-Item -Path $env:LOCALAPPDATA\Temp -ItemType SymbolicLink -Value $env:SystemDrive\Temp -Force - } - - # Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp - # The additional registry key creating are needed to fix the property type of the keys: SetEnvironmentVariable creates them with the "String" type instead of "ExpandString" as by default - [Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "User") - [Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "Machine") - [Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "Process") - New-ItemProperty -Path HKCU:\Environment -Name TMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force - - [Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "User") - [Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "Machine") - [Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "Process") - New-ItemProperty -Path HKCU:\Environment -Name TEMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force - - New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TMP -PropertyType ExpandString -Value $env:SystemDrive\Temp -Force - } - "Default" - { - # PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word - # https://github.com/PowerShell/PowerShell/issues/21070 - if ((Get-Item -Path $env:TEMP).FullName -eq "$env:LOCALAPPDATA\Temp") - { - Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message $Localization.Skipped -Verbose - - return - } - - # Restart the Printer Spooler service (Spooler) - Restart-Service -Name Spooler -Force - - # Stop OneDrive processes - Stop-Process -Name OneDrive, FileCoAuth -Force -ErrorAction Ignore - - # Remove a symbolic link to the %SystemDrive%\Temp folder - if (Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"}) - { - (Get-Item -Path $env:LOCALAPPDATA\Temp -Force).Delete() - } - - if (-not (Test-Path -Path $env:SystemRoot\Temp)) - { - New-Item -Path $env:SystemRoot\Temp -ItemType Directory -Force - } - if (-not (Test-Path -Path $env:LOCALAPPDATA\Temp)) - { - New-Item -Path $env:LOCALAPPDATA\Temp -ItemType Directory -Force - } - - # Removing folders - # PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word - # https://github.com/PowerShell/PowerShell/issues/21070 - Remove-Item -Path $((Get-Item -Path $env:TEMP).FullName) -Recurse -Force -ErrorAction Ignore - - if ((Get-ChildItem -Path $env:TEMP -Force -ErrorAction Ignore | Measure-Object).Count -ne 0) - { - # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa - # The system does not move the file until the operating system is restarted - # The system moves the file immediately after AUTOCHK is executed, but before creating any paging files - $Signature = @{ - Namespace = "WinAPI" - Name = "DeleteFiles" - Language = "CSharp" - CompilerParameters = $CompilerParameters - MemberDefinition = @" -public enum MoveFileFlags -{ - MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 -} - -[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] -static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags); - -public static bool MarkFileDelete (string sourcefile) -{ - return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); -} -"@ - } - - if (-not ("WinAPI.DeleteFiles" -as [type])) - { - Add-Type @Signature - } - - try - { - # PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word - # https://github.com/PowerShell/PowerShell/issues/21070 - Remove-Item -Path $((Get-Item -Path $env:TEMP).FullName) -Recurse -Force -ErrorAction Stop - } - catch - { - # If files are in use remove them at the next boot - Get-ChildItem -Path $env:TEMP -Recurse -Force | ForEach-Object -Process {[WinAPI.DeleteFiles]::MarkFileDelete($_.FullName)} - } - - # PowerShell 5.1 (7.5 too) interprets 8.3 file name literally, if an environment variable contains a non-Latin word - # https://github.com/PowerShell/PowerShell/issues/21070 - $TempFolder = (Get-Item -Path $env:TEMP).FullName - $TempFolderCleanupTask = @" -Remove-Item -Path "$TempFolder" -Recurse -Force -Unregister-ScheduledTask -TaskName TemporaryTask -Confirm:`$false -"@ - - # Create a temporary scheduled task to clean up the temporary folder - # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method - # https://github.com/PowerShell/PowerShell/issues/21377 - $Action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-WindowStyle Hidden -Command $TempFolderCleanupTask" - $Trigger = New-ScheduledTaskTrigger -AtLogon -User $env:USERNAME - $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 - $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$env:USERNAME" -RunLevel Highest - $Parameters = @{ - TaskName = "TemporaryTask" - Principal = $Principal - Action = $Action - Settings = $Settings - Trigger = $Trigger - } - Register-ScheduledTask @Parameters -Force - } - - # Change the %TEMP% environment variable path to %LOCALAPPDATA%\Temp - [Environment]::SetEnvironmentVariable("TMP", "$env:LOCALAPPDATA\Temp", "User") - [Environment]::SetEnvironmentVariable("TMP", "$env:SystemRoot\TEMP", "Machine") - [Environment]::SetEnvironmentVariable("TMP", "$env:LOCALAPPDATA\Temp", "Process") - New-ItemProperty -Path HKCU:\Environment -Name TMP -PropertyType ExpandString -Value "%USERPROFILE%\AppData\Local\Temp" -Force - - [Environment]::SetEnvironmentVariable("TEMP", "$env:LOCALAPPDATA\Temp", "User") - [Environment]::SetEnvironmentVariable("TEMP", "$env:SystemRoot\TEMP", "Machine") - [Environment]::SetEnvironmentVariable("TEMP", "$env:LOCALAPPDATA\Temp", "Process") - New-ItemProperty -Path HKCU:\Environment -Name TEMP -PropertyType ExpandString -Value "%USERPROFILE%\AppData\Local\Temp" -Force - - New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TMP -PropertyType ExpandString -Value "%SystemRoot%\TEMP" -Force - New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TEMP -PropertyType ExpandString -Value "%SystemRoot%\TEMP" -Force - } - } -} - <# .SYNOPSIS The Windows 260 character path limit @@ -8360,6 +8068,24 @@ function RecommendedTroubleshooting New-Item -Path HKLM:\SOFTWARE\Microsoft\WindowsMitigation -Force } New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsMitigation -Name UserPreference -PropertyType DWord -Value 3 -Force + + # Set Windows level of diagnostic data gathering to "Optional diagnostic data" + if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack)) + { + New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Force + } + New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 3 -Force + New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 3 -Force + New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 3 -Force + + Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWORD -Value 3 + + # Turn on Windows Error Reporting + Get-ScheduledTask -TaskName QueueReporting | Enable-ScheduledTask + Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore + + Get-Service -Name WerSvc | Set-Service -StartupType Manual + Get-Service -Name WerSvc | Start-Service } "Default" { @@ -8370,24 +8096,6 @@ function RecommendedTroubleshooting New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WindowsMitigation -Name UserPreference -PropertyType DWord -Value 2 -Force } } - - # Set Windows level of diagnostic data gathering to "Optional diagnostic data" - if (-not (Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack)) - { - New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Force - } - New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -PropertyType DWord -Value 3 -Force - New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection -Name MaxTelemetryAllowed -PropertyType DWord -Value 3 -Force - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack -Name ShowedToastAtLevel -PropertyType DWord -Value 3 -Force - - Set-Policy -Scope Computer -Path SOFTWARE\Policies\Microsoft\Windows\DataCollection -Name AllowTelemetry -Type DWORD -Value 1 - - # Turn on Windows Error Reporting - Get-ScheduledTask -TaskName QueueReporting | Enable-ScheduledTask - Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name Disabled -Force -ErrorAction Ignore - - Get-Service -Name WerSvc | Set-Service -StartupType Manual - Get-Service -Name WerSvc | Start-Service } <# @@ -10849,7 +10557,7 @@ function Install-WSL UseBasicParsing = $true Verbose = $true } - (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { + $Distros = (Invoke-RestMethod @Parameters).Distributions | ForEach-Object -Process { [PSCustomObject]@{ "Distro" = $_.FriendlyName "Alias" = $_.Name @@ -11833,316 +11541,6 @@ function UninstallUWPApps } } -<# - .SYNOPSIS - Restore the default UWP apps - - .EXAMPLE - RestoreUWPAppsUWPApps - - .NOTES - UWP apps can be restored only if they were uninstalled for the current user - - .NOTES - Current user -#> -function RestoreUWPApps -{ - Add-Type -AssemblyName PresentationCore, PresentationFramework - - #region Variables - #region XAML Markup - # The section defines the design of the upcoming dialog box - [xml]$XAML = @" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -