diff --git a/config/tweaks.json b/config/tweaks.json index 32d96705..bfad4d80 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -40,6 +40,9 @@ "Value": "0", "OriginalValue": "1" } + ], + "InvokeScript": [ + "powercfg.exe /hibernate off" ] }, "WPFEssTweaksHome": { @@ -92,7 +95,7 @@ "service": [ { "Name": "AJRouter", - "StartupType": "Manual", + "StartupType": "Disabled", "OriginalType": "Manual" }, { @@ -132,7 +135,7 @@ }, { "Name": "AssignedAccessManagerSvc", - "StartupType": "Manual", + "StartupType": "Disabled", "OriginalType": "Manual" }, { @@ -737,7 +740,7 @@ }, { "Name": "SCardSvr", - "StartupType": "Disabled", + "StartupType": "Manual", "OriginalType": "Manual" }, { @@ -887,8 +890,8 @@ }, { "Name": "TermService", - "StartupType": "Manual", - "OriginalType": "Manual" + "StartupType": "Automatic", + "OriginalType": "Automatic" }, { "Name": "TextInputManagementService", @@ -1217,7 +1220,7 @@ }, { "Name": "dmwappushservice", - "StartupType": "Disabled", + "StartupType": "Manual", "OriginalType": "Manual" }, { @@ -1838,23 +1841,6 @@ "type": "String" } ], - "service": [ - { - "Name": "DiagTrack", - "StartupType": "Disabled", - "OriginalType": "Automatic" - }, - { - "Name": "dmwappushservice", - "StartupType": "Disabled", - "OriginalType": "Manual" - }, - { - "Name": "SysMain", - "StartupType": "Disabled", - "OriginalType": "Manual" - } - ], "InvokeScript": [ "bcdedit /set `{current`} bootmenupolicy Legacy | Out-Null If ((get-ItemProperty -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" -Name CurrentBuild).CurrentBuild -lt 22557) { @@ -1878,9 +1864,6 @@ Remove-Item \"$autoLoggerDir\\AutoLogger-Diagtrack-Listener.etl\" } icacls $autoLoggerDir /deny SYSTEM:`(OI`)`(CI`)F | Out-Null - - $ram = (Get-CimInstance -ClassName \"Win32_PhysicalMemory\" | Measure-Object -Property Capacity -Sum).Sum / 1kb - Set-ItemProperty -Path \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\" -Name \"SvcHostSplitThresholdInKB\" -Type DWord -Value $ram -Force " ] }, @@ -2237,7 +2220,10 @@ }, "WPFEssTweaksDiskCleanup": { "InvokeScript": [ - "cleanmgr.exe /d C: /VERYLOWDISK" + " + cleanmgr.exe /d C: /VERYLOWDISK + Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase + " ] }, "WPFMiscTweaksDisableTPMCheck": { @@ -2374,11 +2360,7 @@ "Value": "0", "OriginalValue": "1", "Type": "DWord" - } - ] - }, - "WPFDisableGameBar": { - "registry": [ + }, { "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Windows\\GameDVR", "Name": "AllowGameDVR", diff --git a/edgeremoval.bat b/edgeremoval.bat index a086a2f2..13493beb 100644 --- a/edgeremoval.bat +++ b/edgeremoval.bat @@ -67,11 +67,18 @@ foreach ($i in $remove_appx) { dir "$store\EndOfLife" -rec -ea 0 |where {$_ -like "*${i}*"} |foreach {cmd /c "reg delete ""$($_.Name)"" /f >nul 2>nul"} dir "$store\Deleted\EndOfLife" -rec -ea 0 |where {$_ -like "*${i}*"} |foreach {cmd /c "reg delete ""$($_.Name)"" /f >nul 2>nul"} } + ## extra cleanup -$desktop = $([Environment]::GetFolderPath('Desktop')); $appdata = $([Environment]::GetFolderPath('ApplicationData')) +$appdata = $([Environment]::GetFolderPath('ApplicationData')) +$desktop = $([Environment]::GetFolderPath('Desktop')) +$public_desktop = $([Environment]::GetFolderPath('CommonDesktopDirectory')) +$start_menu_programs = $([Environment]::GetFolderPath('CommonPrograms')) del "$appdata\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk" -force -ea 0 +del "$appdata\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk" -force -ea 0 del "$appdata\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk" -force -ea 0 del "$desktop\Microsoft Edge.lnk" -force -ea 0 +del "$public_desktop\Microsoft Edge.lnk" -force -ea 0 +del "$start_menu_programs\Microsoft Edge.lnk" -force -ea 0 ## add OpenWebSearch to redirect microsoft-edge: anti-competitive links to the default browser $IFEO = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options' diff --git a/functions/private/Get-WinUtilDarkMode.ps1 b/functions/private/Get-WinUtilDarkMode.ps1 deleted file mode 100644 index bc2fab83..00000000 --- a/functions/private/Get-WinUtilDarkMode.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -Function Get-WinUtilDarkMode { - <# - - .DESCRIPTION - Meant to pull the registry keys responsible for Dark Mode and returns true or false - - #> - $app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme - $system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme - if($app -eq 0 -and $system -eq 0){ - return $true - } - else{ - return $false - } -} \ No newline at end of file diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 new file mode 100644 index 00000000..a9742ff5 --- /dev/null +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -0,0 +1,32 @@ +Function Get-WinUtilToggleStatus { + <# + + .DESCRIPTION + Meant to pull the registry keys for a toggle switch and returns true or false + + True should mean status is enabled + False should mean status is disabled + + #> + + Param($ToggleSwitch) + if($ToggleSwitch -eq "WPFToggleDarkMode"){ + $app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme + $system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme + if($app -eq 0 -and $system -eq 0){ + return $true + } + else{ + return $false + } + } + if($ToggleSwitch -eq "WPFToggleBingSearch"){ + $bingsearch = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search').BingSearchEnabled + if($bingsearch -eq 0){ + return $false + } + else{ + return $true + } + } +} \ No newline at end of file diff --git a/functions/private/Install-WinUtilWinget.ps1 b/functions/private/Install-WinUtilWinget.ps1 index b62c172b..1ca33d99 100644 --- a/functions/private/Install-WinUtilWinget.ps1 +++ b/functions/private/Install-WinUtilWinget.ps1 @@ -1,3 +1,12 @@ +function Get-LatestHash { + $shaUrl = ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt$' }).browser_download_url + + $shaFile = Join-Path -Path $tempFolder -ChildPath 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt' + $WebClient.DownloadFile($shaUrl, $shaFile) + + Get-Content $shaFile + } + function Install-WinUtilWinget { <# @@ -28,46 +37,63 @@ function Install-WinUtilWinget { return } - #Gets the Windows Edition - $OSName = if ($ComputerInfo.OSName) { - $ComputerInfo.OSName - }else { - $ComputerInfo.WindowsProductName + Write-Host "Running Alternative Installer and Direct Installing" + $ErrorActionPreference = "Stop" + $apiLatestUrl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + + # Hide the progress bar of Invoke-WebRequest + $oldProgressPreference = $ProgressPreference + $ProgressPreference = 'SilentlyContinue' + + $desktopAppInstaller = @{ + fileName = 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle' + url = $(((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle$' }).browser_download_url) + hash = $(Get-LatestHash) } - if (((($OSName.IndexOf("LTSC")) -ne -1) -or ($OSName.IndexOf("Server") -ne -1)) -and (($ComputerInfo.WindowsVersion) -ge "1809")) { - - Write-Host "Running Alternative Installer for LTSC/Server Editions" - - # Switching to winget-install from PSGallery from asheroto - # Source: https://github.com/asheroto/winget-installer - - #adding the code from the asheroto repo - Set-ExecutionPolicy RemoteSigned -force - Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted - Install-Script -Name winget-install -force - winget-instal - - - Start-Process powershell.exe -Verb RunAs -ArgumentList "-command irm https://raw.githubusercontent.com/ChrisTitusTech/winutil/$BranchToUse/winget.ps1 | iex | Out-Host" -WindowStyle Normal -ErrorAction Stop - - if(!(Test-WinUtilPackageManager -winget)){ - break + $vcLibsUwp = @{ + fileName = 'Microsoft.VCLibs.x64.14.00.Desktop.appx' + url = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx' + hash = '6602159c341bafea747d0edf15669ac72df8817299fbfaa90469909e06794256' + } + $uiLibs = @{ + nupkg = @{ + fileName = 'microsoft.ui.xaml.2.7.0.nupkg' + url = 'https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0' + hash = "422FD24B231E87A842C4DAEABC6A335112E0D35B86FAC91F5CE7CF327E36A591" + } + uwp = @{ + fileName = 'Microsoft.UI.Xaml.2.7.appx' } } + $uiLibs.uwp.file = $PWD.Path + '\' + $uiLibs.uwp.fileName + $uiLibs.uwp.zipPath = '*/x64/*/' + $uiLibs.uwp.fileName - else { - #Installing Winget from the Microsoft Store - Write-Host "Winget not found, installing it now." - Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget" - $nid = (Get-Process AppInstaller).Id - Wait-Process -Id $nid + $dependencies = @($desktopAppInstaller, $vcLibsUwp, $uiLibs.nupkg) - if(!(Test-WinUtilPackageManager -winget)){ - break - } + foreach ($dependency in $dependencies) { + $dependency.file = $dependency.fileName + Invoke-WebRequest $dependency.url -OutFile $dependency.file } + + $uiLibs.nupkg.file = $PSScriptRoot + '\' + $uiLibs.nupkg.fileName + Add-Type -Assembly System.IO.Compression.FileSystem + $uiLibs.nupkg.zip = [IO.Compression.ZipFile]::OpenRead($uiLibs.nupkg.file) + $uiLibs.nupkg.zipUwp = $uiLibs.nupkg.zip.Entries | Where-Object { $_.FullName -like $uiLibs.uwp.zipPath } + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($uiLibs.nupkg.zipUwp, $uiLibs.uwp.file, $true) + $uiLibs.nupkg.zip.Dispose() + + Add-AppxPackage -Path $desktopAppInstaller.file -DependencyPath $vcLibsUwp.file,$uiLibs.uwp.file + + Remove-Item $desktopAppInstaller.file + Remove-Item $vcLibsUwp.file + Remove-Item $uiLibs.nupkg.file + Remove-Item $uiLibs.uwp.file + Write-Host "WinGet installed!" -ForegroundColor Green + $ProgressPreference = $oldProgressPreference + Update-EnvironmentVariables + Write-Host "Winget Installed" } Catch{ diff --git a/functions/private/Invoke-WinUtilBingSearch.ps1 b/functions/private/Invoke-WinUtilBingSearch.ps1 new file mode 100644 index 00000000..9d6fb56a --- /dev/null +++ b/functions/private/Invoke-WinUtilBingSearch.ps1 @@ -0,0 +1,31 @@ +function Invoke-WinUtilBingSearch { + <# + + .DESCRIPTION + Sets Bing Search on or off + + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Bing Search" + $value = 1 + } + else { + Write-Host "Disabling Bing Search" + $value = 0 + } + $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" + Set-ItemProperty -Path $Path -Name BingSearchEnabled -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 + } +} \ No newline at end of file diff --git a/functions/public/Invoke-WPFDarkMode.ps1 b/functions/private/Invoke-WinUtilDarkMode.ps1 similarity index 96% rename from functions/public/Invoke-WPFDarkMode.ps1 rename to functions/private/Invoke-WinUtilDarkMode.ps1 index fd7753b7..c8002477 100644 --- a/functions/public/Invoke-WPFDarkMode.ps1 +++ b/functions/private/Invoke-WinUtilDarkMode.ps1 @@ -1,4 +1,4 @@ -Function Invoke-WPFDarkMode { +Function Invoke-WinUtilDarkMode { <# .DESCRIPTION diff --git a/functions/private/Update-EnvironmentVariables b/functions/private/Update-EnvironmentVariables new file mode 100644 index 00000000..3fb6dcfc --- /dev/null +++ b/functions/private/Update-EnvironmentVariables @@ -0,0 +1,18 @@ +<# + + .DESCRIPTION + Updates Path Variables for the current session + + #> + +function Update-EnvironmentVariables { + foreach($level in "Machine","User") { + [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % { + # For Path variables, append the new values, if they're not already in there + if($_.Name -match 'Path$') { + $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select-Object -unique) -join ';' + } + $_ + } | Set-Content -Path { "Env:$($_.Name)" } + } +} \ No newline at end of file diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 new file mode 100644 index 00000000..451c950d --- /dev/null +++ b/functions/public/Invoke-WPFToggle.ps1 @@ -0,0 +1,23 @@ +function Invoke-WPFToggle { + + <# + + .DESCRIPTION + Meant to make creating toggle switches easier. There is a section below in the gui that will assign this function to every switch. + This way you can dictate what each button does from this function. + + Input will be the name of the toggle that is checked. + #> + + Param ([string]$Button) + + #Use this to get the name of the button + #[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info") + + Switch -Wildcard ($Button){ + + "WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)} + "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)} + + } +} \ No newline at end of file diff --git a/ooshutup10_winutil_settings.cfg b/ooshutup10_winutil_settings.cfg index e0675fcc..f38a4a33 100644 --- a/ooshutup10_winutil_settings.cfg +++ b/ooshutup10_winutil_settings.cfg @@ -1,5 +1,5 @@ ############################################################################ -# This file was created with O&O ShutUp10++ V1.9.1434 +# This file was created with O&O ShutUp10++ V1.9.1435 # and can be imported onto another computer. # # Download the application at https://www.oo-software.com/shutup10 @@ -13,7 +13,7 @@ # user does not get any feedback about the import. # # We are always happy to answer any questions you may have! -# © 2015-2022 O&O Software GmbH, Berlin. All rights reserved. +# © 2015-2023 O&O Software GmbH, Berlin. All rights reserved. # https://www.oo-software.com/ ############################################################################ @@ -57,7 +57,7 @@ P013 - P035 - P062 - P063 - -P081 + +P081 - P047 - P019 - P048 - @@ -102,7 +102,7 @@ P077 - P078 - P079 - P080 - -P024 + +P024 - S001 + S002 + S003 + @@ -123,12 +123,14 @@ E109 + E209 + E121 + E221 - -E103 + +E103 - E203 - E123 - E223 + E124 - E224 - +E128 - +E228 - E119 - E219 - E120 - @@ -145,10 +147,10 @@ E127 - E227 - E001 + E002 + -E003 + +E003 - E008 + E007 + -E010 + +E010 - E011 + E012 + E009 - @@ -157,22 +159,6 @@ E005 - E013 - E014 - E006 - -F002 - -F014 + -F015 - -F016 - -F001 - -F003 + -F004 + -F005 + -F007 - -F008 - -F009 - -F006 - -F010 - -F011 - -F012 - -F013 - Y001 + Y002 + Y003 + @@ -222,6 +208,7 @@ M022 + M001 + M004 + M005 + +M024 - M003 - M012 - M013 - @@ -234,4 +221,3 @@ M019 - M020 + M021 - N001 - - diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 2027612f..8c2c4bcb 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: MIT + #Configure max thread count for RunspacePool. $maxthreads = [int]$env:NUMBER_OF_PROCESSORS @@ -47,14 +49,14 @@ $sync.runspace.Open() #endregion exception classes $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^ - $app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme - $system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme - if($app -eq 0 -and $system -eq 0){ - return $true - } - else{ - return $false - } -} function Get-WinUtilInstallerProcess { <# @@ -167,6 +151,38 @@ function Get-WinUtilRegistry { Write-Warning $psitem.Exception.StackTrace } } +Function Get-WinUtilToggleStatus { + <# + + .DESCRIPTION + Meant to pull the registry keys for a toggle switch and returns true or false + + True should mean status is enabled + False should mean status is disabled + + #> + + Param($ToggleSwitch) + if($ToggleSwitch -eq "WPFToggleDarkMode"){ + $app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme + $system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme + if($app -eq 0 -and $system -eq 0){ + return $true + } + else{ + return $false + } + } + if($ToggleSwitch -eq "WPFToggleBingSearch"){ + $bingsearch = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search').BingSearchEnabled + if($bingsearch -eq 0){ + return $false + } + else{ + return $true + } + } +} function Get-WinUtilVariables { <# @@ -263,6 +279,15 @@ Function Install-WinUtilProgramWinget { Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed } +function Get-LatestHash { + $shaUrl = ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt$' }).browser_download_url + + $shaFile = Join-Path -Path $tempFolder -ChildPath 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt' + $WebClient.DownloadFile($shaUrl, $shaFile) + + Get-Content $shaFile + } + function Install-WinUtilWinget { <# @@ -293,52 +318,100 @@ function Install-WinUtilWinget { return } - #Gets the Windows Edition - $OSName = if ($ComputerInfo.OSName) { - $ComputerInfo.OSName - }else { - $ComputerInfo.WindowsProductName + Write-Host "Running Alternative Installer and Direct Installing" + $ErrorActionPreference = "Stop" + $apiLatestUrl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + + # Hide the progress bar of Invoke-WebRequest + $oldProgressPreference = $ProgressPreference + $ProgressPreference = 'SilentlyContinue' + + $desktopAppInstaller = @{ + fileName = 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle' + url = $(((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle$' }).browser_download_url) + hash = $(Get-LatestHash) } - if (((($OSName.IndexOf("LTSC")) -ne -1) -or ($OSName.IndexOf("Server") -ne -1)) -and (($ComputerInfo.WindowsVersion) -ge "1809")) { - - Write-Host "Running Alternative Installer for LTSC/Server Editions" - - # Switching to winget-install from PSGallery from asheroto - # Source: https://github.com/asheroto/winget-installer - - #adding the code from the asheroto repo - Set-ExecutionPolicy RemoteSigned -force - Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted - Install-Script -Name winget-install -force - winget-instal - - - Start-Process powershell.exe -Verb RunAs -ArgumentList "-command irm https://raw.githubusercontent.com/ChrisTitusTech/winutil/$BranchToUse/winget.ps1 | iex | Out-Host" -WindowStyle Normal -ErrorAction Stop - - if(!(Test-WinUtilPackageManager -winget)){ - break + $vcLibsUwp = @{ + fileName = 'Microsoft.VCLibs.x64.14.00.Desktop.appx' + url = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx' + hash = '6602159c341bafea747d0edf15669ac72df8817299fbfaa90469909e06794256' + } + $uiLibs = @{ + nupkg = @{ + fileName = 'microsoft.ui.xaml.2.7.0.nupkg' + url = 'https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0' + hash = "422FD24B231E87A842C4DAEABC6A335112E0D35B86FAC91F5CE7CF327E36A591" + } + uwp = @{ + fileName = 'Microsoft.UI.Xaml.2.7.appx' } } + $uiLibs.uwp.file = $PWD.Path + '\' + $uiLibs.uwp.fileName + $uiLibs.uwp.zipPath = '*/x64/*/' + $uiLibs.uwp.fileName - else { - #Installing Winget from the Microsoft Store - Write-Host "Winget not found, installing it now." - Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget" - $nid = (Get-Process AppInstaller).Id - Wait-Process -Id $nid + $dependencies = @($desktopAppInstaller, $vcLibsUwp, $uiLibs.nupkg) - if(!(Test-WinUtilPackageManager -winget)){ - break - } + foreach ($dependency in $dependencies) { + $dependency.file = $dependency.fileName + Invoke-WebRequest $dependency.url -OutFile $dependency.file } + + $uiLibs.nupkg.file = $PSScriptRoot + '\' + $uiLibs.nupkg.fileName + Add-Type -Assembly System.IO.Compression.FileSystem + $uiLibs.nupkg.zip = [IO.Compression.ZipFile]::OpenRead($uiLibs.nupkg.file) + $uiLibs.nupkg.zipUwp = $uiLibs.nupkg.zip.Entries | Where-Object { $_.FullName -like $uiLibs.uwp.zipPath } + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($uiLibs.nupkg.zipUwp, $uiLibs.uwp.file, $true) + $uiLibs.nupkg.zip.Dispose() + + Add-AppxPackage -Path $desktopAppInstaller.file -DependencyPath $vcLibsUwp.file,$uiLibs.uwp.file + + Remove-Item $desktopAppInstaller.file + Remove-Item $vcLibsUwp.file + Remove-Item $uiLibs.nupkg.file + Remove-Item $uiLibs.uwp.file + Write-Host "WinGet installed!" -ForegroundColor Green + $ProgressPreference = $oldProgressPreference + Update-EnvironmentVariables + Write-Host "Winget Installed" } Catch{ throw [WingetFailedInstall]::new('Failed to install') } } +function Invoke-WinUtilBingSearch { + <# + + .DESCRIPTION + Sets Bing Search on or off + + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Bing Search" + $value = 1 + } + else { + Write-Host "Disabling Bing Search" + $value = 0 + } + $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" + Set-ItemProperty -Path $Path -Name BingSearchEnabled -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-WinUtilCurrentSystem { <# @@ -443,6 +516,39 @@ Function Invoke-WinUtilCurrentSystem { } } +Function Invoke-WinUtilDarkMode { + <# + + .DESCRIPTION + Sets Dark Mode on or off + + #> + Param($DarkMoveEnabled) + Try{ + if ($DarkMoveEnabled -eq $false){ + Write-Host "Enabling Dark Mode" + $DarkMoveValue = 0 + } + else { + Write-Host "Disabling Dark Mode" + $DarkMoveValue = 1 + } + + $Theme = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" + Set-ItemProperty -Path $Theme -Name AppsUseLightTheme -Value $DarkMoveValue + Set-ItemProperty -Path $Theme -Name SystemUsesLightTheme -Value $DarkMoveValue + } + 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-WinUtilFeatureInstall { <# @@ -863,6 +969,24 @@ function Test-WinUtilPackageManager { return $false } +<# + + .DESCRIPTION + Updates Path Variables for the current session + + #> + +function Update-EnvironmentVariables { + foreach($level in "Machine","User") { + [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % { + # For Path variables, append the new values, if they're not already in there + if($_.Name -match 'Path$') { + $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select-Object -unique) -join ';' + } + $_ + } | Set-Content -Path { "Env:$($_.Name)" } + } +} Function Update-WinUtilProgramWinget { <# @@ -958,39 +1082,6 @@ function Invoke-WPFControlPanel { "WPFPaneluser" {cmd /c "control userpasswords2"} } } -Function Invoke-WPFDarkMode { - <# - - .DESCRIPTION - Sets Dark Mode on or off - - #> - Param($DarkMoveEnabled) - Try{ - if ($DarkMoveEnabled -eq $false){ - Write-Host "Enabling Dark Mode" - $DarkMoveValue = 0 - } - else { - Write-Host "Disabling Dark Mode" - $DarkMoveValue = 1 - } - - $Theme = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" - Set-ItemProperty -Path $Theme -Name AppsUseLightTheme -Value $DarkMoveValue - Set-ItemProperty -Path $Theme -Name SystemUsesLightTheme -Value $DarkMoveValue - } - 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-WPFFeatureInstall { <# @@ -1511,6 +1602,29 @@ function Invoke-WPFTab { } } } +function Invoke-WPFToggle { + + <# + + .DESCRIPTION + Meant to make creating toggle switches easier. There is a section below in the gui that will assign this function to every switch. + This way you can dictate what each button does from this function. + + Input will be the name of the toggle that is checked. + #> + + Param ([string]$Button) + + #Use this to get the name of the button + #[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info") + + Switch -Wildcard ($Button){ + + "WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)} + "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)} + + } +} function Invoke-WPFtweaksbutton { <# @@ -2474,6 +2588,12 @@ $inputXML = '