From 45ec574221d6ac33c1e5f03f5ebfbe7dbf2b1e70 Mon Sep 17 00:00:00 2001 From: Rux Date: Sun, 31 Mar 2024 10:03:48 -0700 Subject: [PATCH 01/11] Winget Sources fix (#1773) - Sometimes, if Winget is installed under user-scope, the source isn't properly installed so that the Admin user can properly use Winget. - This change installs the sources directly from the Winget CDN. - Fixes #1771 https://github.com/microsoft/winget-cli/discussions/3258#discussioncomment-5951658 --- functions/private/Install-WinUtilWinget.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/private/Install-WinUtilWinget.ps1 b/functions/private/Install-WinUtilWinget.ps1 index a0c7b7bd..2bdba08e 100644 --- a/functions/private/Install-WinUtilWinget.ps1 +++ b/functions/private/Install-WinUtilWinget.ps1 @@ -40,6 +40,8 @@ function Install-WinUtilWinget { Get-WinUtilWingetLatest Write-Host "Installing Winget w/ Prerequsites`r" Add-AppxProvisionedPackage -Online -PackagePath $ENV:TEMP\Microsoft.DesktopAppInstaller.msixbundle -DependencyPackagePath $ENV:TEMP\Microsoft.VCLibs.x64.Desktop.appx, $ENV:TEMP\Microsoft.UI.Xaml.x64.appx -LicensePath $ENV:TEMP\License1.xml + Write-Host "Manually adding Winget Sources, from Winget CDN." + Add-AppxPackage -Path https://cdn.winget.microsoft.com/cache/source.msix #Seems some installs of Winget don't add the repo source, this should makes sure that it's installed every time. Write-Host "Winget Installed" -ForegroundColor Green # Winget only needs a refresh of the environment variables to be used. Write-Output "Refreshing Environment Variables...`n" From 28e8db98d311242119316a9d9578e8edd4ed2900 Mon Sep 17 00:00:00 2001 From: ChrisTitusTech Date: Sun, 31 Mar 2024 17:04:12 +0000 Subject: [PATCH 02/11] Compile Winutil --- winutil.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/winutil.ps1 b/winutil.ps1 index 2f5d7f82..cb89707f 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -10,7 +10,7 @@ Author : Chris Titus @christitustech Runspace Author: @DeveloperDurp GitHub : https://github.com/ChrisTitusTech - Version : 24.03.30 + Version : 24.03.31 #> param ( [switch]$Debug, @@ -47,7 +47,7 @@ Add-Type -AssemblyName System.Windows.Forms # Variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot -$sync.version = "24.03.30" +$sync.version = "24.03.31" $sync.configs = @{} $sync.ProcessRunning = $false @@ -777,6 +777,8 @@ function Install-WinUtilWinget { Get-WinUtilWingetLatest Write-Host "Installing Winget w/ Prerequsites`r" Add-AppxProvisionedPackage -Online -PackagePath $ENV:TEMP\Microsoft.DesktopAppInstaller.msixbundle -DependencyPackagePath $ENV:TEMP\Microsoft.VCLibs.x64.Desktop.appx, $ENV:TEMP\Microsoft.UI.Xaml.x64.appx -LicensePath $ENV:TEMP\License1.xml + Write-Host "Manually adding Winget Sources, from Winget CDN." + Add-AppxPackage -Path https://cdn.winget.microsoft.com/cache/source.msix #Seems some installs of Winget don't add the repo source, this should makes sure that it's installed every time. Write-Host "Winget Installed" -ForegroundColor Green # Winget only needs a refresh of the environment variables to be used. Write-Output "Refreshing Environment Variables...`n" From 07abbba938246e356f898c4572c7ddcf8005ea5b Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:05:16 +0200 Subject: [PATCH 03/11] Finished conversion of DISM commands into DISM cmdlets (#1776) * Continue conversion Began 2nd stage of DISM command conversion. Almost all commands have been replaced by cmdlets * Continue conversion (part 2) Finished part 2 of DISM command to cmdlet conversion --- functions/private/Invoke-MicroWin-Helper.ps1 | 42 ++++++++++-------- functions/public/Invoke-WPFMicrowin.ps1 | 4 +- winutil.ps1 | 46 ++++++++++++-------- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/functions/private/Invoke-MicroWin-Helper.ps1 b/functions/private/Invoke-MicroWin-Helper.ps1 index 3ae08d49..f34adb35 100644 --- a/functions/private/Invoke-MicroWin-Helper.ps1 +++ b/functions/private/Invoke-MicroWin-Helper.ps1 @@ -54,38 +54,39 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender Remove-Features -keepDefender:$false #> - $appxlist = dism /English /image:$scratchDir /Get-Features | Select-String -Pattern "Feature Name : " -CaseSensitive -SimpleMatch - $appxlist = $appxlist -split "Feature Name : " | Where-Object {$_} + $featlist = (Get-WindowsOptionalFeature -Path $scratchDir).FeatureName if ($dumpFeatures) { - $appxlist > allfeaturesdump.txt + $featlist > allfeaturesdump.txt } - $appxlist = $appxlist | Where-Object { + $featlist = $featlist | Where-Object { $_ -NotLike "*Printing*" -AND $_ -NotLike "*TelnetClient*" -AND $_ -NotLike "*PowerShell*" -AND - $_ -NotLike "*NetFx*" + $_ -NotLike "*NetFx*" -AND + $_ -NotLike "*Media*" -AND + $_ -NotLike "*NFS*" } - if ($keepDefender) { $appxlist = $appxlist | Where-Object { $_ -NotLike "*Defender*" }} + if ($keepDefender) { $featlist = $featlist | Where-Object { $_ -NotLike "*Defender*" }} - foreach($feature in $appxlist) + foreach($feature in $featlist) { $status = "Removing feature $feature" - Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$appxlist.Count*100) + Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$featlist.Count*100) Write-Debug "Removing feature $feature" - # dism /image:$scratchDir /Disable-Feature /FeatureName:$feature /Remove /NoRestart > $null + Disable-WindowsOptionalFeature -Path "$scratchDir" -FeatureName $feature -Remove -ErrorAction SilentlyContinue -NoRestart } Write-Progress -Activity "Removing features" -Status "Ready" -Completed + Write-Host "You can re-enable the disabled features at any time, using either Windows Update or the SxS folder in \Sources." } function Remove-Packages { - $appxlist = dism /English /Image:$scratchDir /Get-Packages | Select-String -Pattern "Package Identity : " -CaseSensitive -SimpleMatch - $appxlist = $appxlist -split "Package Identity : " | Where-Object {$_} + $pkglist = (Get-WindowsPackage -Path "$scratchDir").PackageName - $appxlist = $appxlist | Where-Object { + $pkglist = $pkglist | Where-Object { $_ -NotLike "*ApplicationModel*" -AND $_ -NotLike "*indows-Client-LanguagePack*" -AND $_ -NotLike "*LanguageFeatures-Basic*" -AND @@ -123,11 +124,18 @@ function Remove-Packages $_ -NotLike "*UI.XaML*" } - foreach ($appx in $appxlist) + foreach ($pkg in $pkglist) { - $status = "Removing $appx" - Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$appxlist.Count*100) - dism /English /image:$scratchDir /Remove-Package /PackageName:$appx /NoRestart + try { + $status = "Removing $pkg" + Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$pkglist.Count*100) + Remove-WindowsPackage -Path "$scratchDir" -PackageName $pkg -NoRestart -ErrorAction SilentlyContinue + } + catch { + # This can happen if the package that is being removed is a permanent one, like FodMetadata + Write-Host "Could not remove OS package $($pkg)" + continue + } } Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed } @@ -167,7 +175,7 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false) { $status = "Removing Provisioned $($appx.PackageName)" Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100) - dism /English /image:$scratchDir /Remove-ProvisionedAppxPackage /PackageName:$($appx.PackageName) /NoRestart + Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue } Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed } diff --git a/functions/public/Invoke-WPFMicrowin.ps1 b/functions/public/Invoke-WPFMicrowin.ps1 index 6c8a2d6a..89d15872 100644 --- a/functions/public/Invoke-WPFMicrowin.ps1 +++ b/functions/public/Invoke-WPFMicrowin.ps1 @@ -117,7 +117,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host + Add-WindowsDriver -Path "$scratchDir" -Recurse -Driver "$driverPath" } else { @@ -335,7 +335,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host + Add-WindowsDriver -Path "$scratchDir" -Driver "$driverPath" -Recurse } else { diff --git a/winutil.ps1 b/winutil.ps1 index cb89707f..c884492d 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -852,38 +852,39 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender Remove-Features -keepDefender:$false #> - $appxlist = dism /English /image:$scratchDir /Get-Features | Select-String -Pattern "Feature Name : " -CaseSensitive -SimpleMatch - $appxlist = $appxlist -split "Feature Name : " | Where-Object {$_} + $featlist = (Get-WindowsOptionalFeature -Path $scratchDir).FeatureName if ($dumpFeatures) { - $appxlist > allfeaturesdump.txt + $featlist > allfeaturesdump.txt } - $appxlist = $appxlist | Where-Object { + $featlist = $featlist | Where-Object { $_ -NotLike "*Printing*" -AND $_ -NotLike "*TelnetClient*" -AND $_ -NotLike "*PowerShell*" -AND - $_ -NotLike "*NetFx*" + $_ -NotLike "*NetFx*" -AND + $_ -NotLike "*Media*" -AND + $_ -NotLike "*NFS*" } - if ($keepDefender) { $appxlist = $appxlist | Where-Object { $_ -NotLike "*Defender*" }} + if ($keepDefender) { $featlist = $featlist | Where-Object { $_ -NotLike "*Defender*" }} - foreach($feature in $appxlist) + foreach($feature in $featlist) { $status = "Removing feature $feature" - Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$appxlist.Count*100) + Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$featlist.Count*100) Write-Debug "Removing feature $feature" - # dism /image:$scratchDir /Disable-Feature /FeatureName:$feature /Remove /NoRestart > $null + Disable-WindowsOptionalFeature -Path "$scratchDir" -FeatureName $feature -Remove -ErrorAction SilentlyContinue -NoRestart } Write-Progress -Activity "Removing features" -Status "Ready" -Completed + Write-Host "You can re-enable the disabled features at any time, using either Windows Update or the SxS folder in \Sources." } function Remove-Packages { - $appxlist = dism /English /Image:$scratchDir /Get-Packages | Select-String -Pattern "Package Identity : " -CaseSensitive -SimpleMatch - $appxlist = $appxlist -split "Package Identity : " | Where-Object {$_} + $pkglist = (Get-WindowsPackage -Path "$scratchDir").PackageName - $appxlist = $appxlist | Where-Object { + $pkglist = $pkglist | Where-Object { $_ -NotLike "*ApplicationModel*" -AND $_ -NotLike "*indows-Client-LanguagePack*" -AND $_ -NotLike "*LanguageFeatures-Basic*" -AND @@ -921,11 +922,18 @@ function Remove-Packages $_ -NotLike "*UI.XaML*" } - foreach ($appx in $appxlist) + foreach ($pkg in $pkglist) { - $status = "Removing $appx" - Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$appxlist.Count*100) - dism /English /image:$scratchDir /Remove-Package /PackageName:$appx /NoRestart + try { + $status = "Removing $pkg" + Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$pkglist.Count*100) + Remove-WindowsPackage -Path "$scratchDir" -PackageName $pkg -NoRestart -ErrorAction SilentlyContinue + } + catch { + # This can happen if the package that is being removed is a permanent one, like FodMetadata + Write-Host "Could not remove OS package $($pkg)" + continue + } } Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed } @@ -965,7 +973,7 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false) { $status = "Removing Provisioned $($appx.PackageName)" Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100) - dism /English /image:$scratchDir /Remove-ProvisionedAppxPackage /PackageName:$($appx.PackageName) /NoRestart + Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue } Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed } @@ -3696,7 +3704,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host + Add-WindowsDriver -Path "$scratchDir" -Recurse -Driver "$driverPath" } else { @@ -3914,7 +3922,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host + Add-WindowsDriver -Path "$scratchDir" -Driver "$driverPath" -Recurse } else { From 25ce9df16f5cad81e7c6e018813f2bb766eb2edb Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Sun, 31 Mar 2024 20:07:36 +0300 Subject: [PATCH 04/11] Add New Toggle to Disable/Enable Widgets found in Taskbar (#1768) --- config/tweaks.json | 8 +++++ functions/private/Get-WinUtilToggleStatus.ps1 | 11 +++++- .../private/Invoke-WinUtilTaskbarWidgets.ps1 | 34 +++++++++++++++++++ functions/public/Invoke-WPFToggle.ps1 | 3 +- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 functions/private/Invoke-WinUtilTaskbarWidgets.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index cd074d65..445b7477 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -2613,6 +2613,14 @@ "Order": "a067_", "Type": "Toggle" }, + "WPFToggleTaskbarWidgets": { + "Content": "Taskbar Widgets", + "Description": "If Enabled then Widgets Icon in Taskbar will be shown.", + "category": "Customize Preferences", + "panel": "2", + "Order": "a068_", + "Type": "Toggle" + }, "WPFchangedns": { "Content": "DNS", "category": "z__Advanced Tweaks - CAUTION", diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index cc5b5090..95160ef6 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -89,4 +89,13 @@ Function Get-WinUtilToggleStatus { return $true } } -} \ No newline at end of file + if ($ToggleSwitch -eq "WPFToggleTaskbarWidgets") { + $TaskbarWidgets = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskBarDa + if($TaskbarWidgets -eq 0) { + return $false + } + else{ + return $true + } + } +} diff --git a/functions/private/Invoke-WinUtilTaskbarWidgets.ps1 b/functions/private/Invoke-WinUtilTaskbarWidgets.ps1 new file mode 100644 index 00000000..27077f55 --- /dev/null +++ b/functions/private/Invoke-WinUtilTaskbarWidgets.ps1 @@ -0,0 +1,34 @@ +function Invoke-WinUtilTaskbarWidgets { + <# + + .SYNOPSIS + Enable/Disable Taskbar Widgets + + .PARAMETER Enabled + Indicates whether to enable or disable Taskbar Widgets + + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Taskbar Widgets" + $value = 1 + } + else { + Write-Host "Disabling Taskbar Widgets" + $value = 0 + } + $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" + Set-ItemProperty -Path $Path -Name TaskbarDa -Value $value + } + Catch [System.Security.SecurityException] { + Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" + } + Catch [System.Management.Automation.ItemNotFoundException] { + Write-Warning $psitem.Exception.ErrorRecord + } + Catch{ + Write-Warning "Unable to set $Name due to unhandled exception" + Write-Warning $psitem.Exception.StackTrace + } +} diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 index 1a60217e..fd8a82f4 100644 --- a/functions/public/Invoke-WPFToggle.ps1 +++ b/functions/public/Invoke-WPFToggle.ps1 @@ -25,5 +25,6 @@ function Invoke-WPFToggle { "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $(Get-WinUtilToggleStatus WPFToggleSnapFlyout)} "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)} "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $(Get-WinUtilToggleStatus WPFToggleStickyKeys)} + "WPFToggleTaskbarWidgets" {Invoke-WinUtilTaskbarWidgets $(Get-WinUtilToggleStatus WPFToggleTaskbarWidgets)} } -} \ No newline at end of file +} From 70533a3998f318f7e157c3baca573c16a6cac252 Mon Sep 17 00:00:00 2001 From: ChrisTitusTech Date: Sun, 31 Mar 2024 17:07:59 +0000 Subject: [PATCH 05/11] Compile Winutil --- winutil.ps1 | 56 +++++++++++++++++++++++++++++++++++++++++++ xaml/inputTweaks.xaml | 4 ++++ 2 files changed, 60 insertions(+) diff --git a/winutil.ps1 b/winutil.ps1 index c884492d..09c35693 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -575,6 +575,15 @@ Function Get-WinUtilToggleStatus { return $true } } + if ($ToggleSwitch -eq "WPFToggleTaskbarWidgets") { + $TaskbarWidgets = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskBarDa + if($TaskbarWidgets -eq 0) { + return $false + } + else{ + return $true + } + } } function Get-WinUtilVariables { @@ -1929,6 +1938,40 @@ Function Invoke-WinUtilStickyKeys { Write-Warning $psitem.Exception.StackTrace } } +function Invoke-WinUtilTaskbarWidgets { + <# + + .SYNOPSIS + Enable/Disable Taskbar Widgets + + .PARAMETER Enabled + Indicates whether to enable or disable Taskbar Widgets + + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Taskbar Widgets" + $value = 1 + } + else { + Write-Host "Disabling Taskbar Widgets" + $value = 0 + } + $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" + Set-ItemProperty -Path $Path -Name TaskbarDa -Value $value + } + Catch [System.Security.SecurityException] { + Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" + } + Catch [System.Management.Automation.ItemNotFoundException] { + Write-Warning $psitem.Exception.ErrorRecord + } + Catch{ + Write-Warning "Unable to set $Name due to unhandled exception" + Write-Warning $psitem.Exception.StackTrace + } +} function Invoke-WinUtilTweaks { <# @@ -4320,6 +4363,7 @@ function Invoke-WPFToggle { "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $(Get-WinUtilToggleStatus WPFToggleSnapFlyout)} "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)} "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $(Get-WinUtilToggleStatus WPFToggleStickyKeys)} + "WPFToggleTaskbarWidgets" {Invoke-WinUtilTaskbarWidgets $(Get-WinUtilToggleStatus WPFToggleTaskbarWidgets)} } } function Invoke-WPFtweaksbutton { @@ -10182,6 +10226,14 @@ $sync.configs.tweaks = '{ "Order": "a067_", "Type": "Toggle" }, + "WPFToggleTaskbarWidgets": { + "Content": "Taskbar Widgets", + "Description": "If Enabled then Widgets Icon in Taskbar will be shown.", + "category": "Customize Preferences", + "panel": "2", + "Order": "a068_", + "Type": "Toggle" + }, "WPFchangedns": { "Content": "DNS", "category": "z__Advanced Tweaks - CAUTION", @@ -11929,6 +11981,10 @@ $inputXML = ' + +