diff --git a/TargetUser.psm1 b/TargetUser.psm1 new file mode 100644 index 0000000..fdcb467 --- /dev/null +++ b/TargetUser.psm1 @@ -0,0 +1,49 @@ + +function Get-TargetUser( + [Parameter(Mandatory=$false)] + [string]$defaultTargetUserName) +{ + + if (!$defaultTargetUserName){ $defaultTargetUserName = $Env:UserName } + + $newTargetUserName = $defaultTargetUserName + $newTargetUserSID = "" + $validUserSelected = $false + + DO + { + + $userInput = Read-Host "Please enter a username for the installation. Hit to install for $defaultTargetUserName " + + if (!$userInput) { + $newTargetUserName = $defaultTargetUserName + } else { + $newTargetUserName = $userInput + } + + $newTargetUserObject = New-Object System.Security.Principal.NTAccount($newTargetUserName) + try { + $newTargetUserSID = $newTargetUserObject.Translate([System.Security.Principal.SecurityIdentifier]).value + $validUserSelected = $true + } catch { + Write-Warning "Specified user $userInput not found" + } + + } until ($validUserSelected) + + if ($newTargetUserName -eq $Env:UserName){ + $newTargetUserProfileDirectory = $env:USERPROFILE + $newTargetUserLocalAppData = $env:LOCALAPPDATA + } else { + $newTargetUserProfileDirectory = Get-ItemPropertyValue "Registry::HKEY_USERS\$newTargetUserSID\Volatile Environment" -Name USERPROFILE + $newTargetUserLocalAppData = Get-ItemPropertyValue "Registry::HKEY_USERS\$newTargetUserSID\Volatile Environment" -Name LOCALAPPDATA + } + + return [PSCustomObject]@{ + userName = $newTargetUserName + SID = $newTargetUserSID + userProfile = $newTargetUserProfileDirectory + localAppData = $newTargetUserLocalAppData + } + +} diff --git a/install.ps1 b/install.ps1 index 5d513ab..833f834 100644 --- a/install.ps1 +++ b/install.ps1 @@ -10,7 +10,11 @@ param( [switch] $PreRelease ) -function Generate-HelperScript( +Import-Module .\TargetUser.psm1 + +$targetUser = Get-TargetUser + +function New-HelperScript( # The cache folder [Parameter(Mandatory=$true)] [string]$cache) @@ -223,9 +227,9 @@ function GetActiveProfiles( [bool]$isPreview) { if ($isPreview) { - $file = "$env:LocalAppData\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\settings.json" + $file = "$($targetUser.localAppData)\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\settings.json" } else { - $file = "$env:LocalAppData\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" + $file = "$($targetUser.localAppData)\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" } if (-not (Test-Path $file)) { Write-Error "Couldn't find profiles. Please run Windows Terminal at least once after installing it. Exit." @@ -266,16 +270,16 @@ function GetProfileIcon ( } elseif ($profile.icon -like "ms-appdata:///Roaming/*") { #resolve roaming cache if ($isPreview) { - $profilePng = $icon -replace "ms-appdata:///Roaming", "$Env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\RoamingState" -replace "/", "\" + $profilePng = $icon -replace "ms-appdata:///Roaming", "$($targetUser.localAppData)\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\RoamingState" -replace "/", "\" } else { - $profilePng = $icon -replace "ms-appdata:///Roaming", "$Env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState" -replace "/", "\" + $profilePng = $icon -replace "ms-appdata:///Roaming", "$($targetUser.localAppData)\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState" -replace "/", "\" } } elseif ($profile.icon -like "ms-appdata:///Local/*") { #resolve local cache if ($isPreview) { - $profilePng = $icon -replace "ms-appdata:///Local", "$Env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState" -replace "/", "\" + $profilePng = $icon -replace "ms-appdata:///Local", "$($targetUser.localAppData)\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState" -replace "/", "\" } else { - $profilePng = $icon -replace "ms-appdata:///Local", "$Env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" -replace "/", "\" + $profilePng = $icon -replace "ms-appdata:///Local", "$($targetUser.localAppData)\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" -replace "/", "\" } } elseif ($profile.icon -like "ms-appx:///*") { # resolve app cache @@ -366,15 +370,15 @@ function CreateProfileMenuItems( $profileIcon = GetProfileIcon $profile $folder $localCache $icon $isPreview if ($layout -eq "Default") { - $rootKey = "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminal\shell\$guid" - $rootKeyElevated = "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminalAdmin\shell\$guid" + $rootKey = "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminal\shell\$guid" + $rootKeyElevated = "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminalAdmin\shell\$guid" CreateMenuItem $rootKey $name $profileIcon $command $false CreateMenuItem $rootKeyElevated $name $profileIcon $elevated $true } elseif ($layout -eq "Flat") { - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal_$guid" "$name here" $profileIcon $command $false - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin_$guid" "$name here as administrator" $profileIcon $elevated $true - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal_$guid" "$name here" $profileIcon $command $false - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin_$guid" "$name here as administrator" $profileIcon $elevated $true + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal_$guid" "$name here" $profileIcon $command $false + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin_$guid" "$name here as administrator" $profileIcon $elevated $true + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal_$guid" "$name here" $profileIcon $command $false + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin_$guid" "$name here as administrator" $profileIcon $elevated $true } } @@ -387,47 +391,47 @@ function CreateMenuItems( [bool]$includePreview) { $folder = GetProgramFilesFolder $includePreview - $localCache = "$Env:LOCALAPPDATA\Microsoft\WindowsApps\Cache" + $localCache = "$($targetUser.localAppData)\Microsoft\WindowsApps\Cache" if (-not (Test-Path $localCache)) { New-Item $localCache -ItemType Directory | Out-Null } - Generate-HelperScript $localCache + New-HelperScript $localCache $icon = GetWindowsTerminalIcon $folder $localCache if ($layout -eq "Default") { # defaut layout creates two menus - New-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal' -Force | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal' -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here' | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal' -Name 'Icon' -PropertyType String -Value $icon | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal' -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminal' | Out-Null + New-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal" -Force | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal" -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here' | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal" -Name 'Icon' -PropertyType String -Value $icon | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal" -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminal' | Out-Null - New-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal' -Force | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal' -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here' | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal' -Name 'Icon' -PropertyType String -Value $icon | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal' -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminal' | Out-Null + New-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal" -Force | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal" -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here' | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal" -Name 'Icon' -PropertyType String -Value $icon | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal" -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminal' | Out-Null - New-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminal\shell' -Force | Out-Null + New-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminal\shell" -Force | Out-Null - New-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin' -Force | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin' -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here as administrator' | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin' -Name 'Icon' -PropertyType String -Value $icon | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin' -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminalAdmin' | Out-Null + New-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin" -Force | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin" -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here as administrator' | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin" -Name 'Icon' -PropertyType String -Value $icon | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin" -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminalAdmin' | Out-Null - New-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin' -Force | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin' -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here as administrator' | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin' -Name 'Icon' -PropertyType String -Value $icon | Out-Null - New-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin' -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminalAdmin' | Out-Null + New-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin" -Force | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin" -Name 'MUIVerb' -PropertyType String -Value 'Windows Terminal here as administrator' | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin" -Name 'Icon' -PropertyType String -Value $icon | Out-Null + New-ItemProperty -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin" -Name 'ExtendedSubCommandsKey' -PropertyType String -Value 'Directory\\ContextMenus\\MenuTerminalAdmin' | Out-Null - New-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminalAdmin\shell' -Force | Out-Null + New-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminalAdmin\shell" -Force | Out-Null } elseif ($layout -eq "Mini") { $command = """$executable"" -d ""%V.""" $elevated = "wscript.exe ""$localCache/helper.vbs"" ""$executable"" ""%V.""" - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalMini" "Windows Terminal here" $icon $command $false - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdminMini" "Windows Terminal here as administrator" $icon $elevated $true - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalMini" "Windows Terminal here" $icon $command $false - CreateMenuItem "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdminMini" "Windows Terminal here as administrator" $icon $elevated $true + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalMini" "Windows Terminal here" $icon $command $false + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdminMini" "Windows Terminal here as administrator" $icon $elevated $true + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalMini" "Windows Terminal here" $icon $command $false + CreateMenuItem "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdminMini" "Windows Terminal here as administrator" $icon $elevated $true return } @@ -445,18 +449,18 @@ if ((Get-Process -Id $pid).Path -like "*WindowsApps*") { exit 1 } -if ((Test-Path "Registry::HKEY_CLASSES_ROOT\Directory\shell\MenuTerminal") -and - -not (Test-Path "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal")) { - Write-Error "Please execute uninstall.old.ps1 to remove previous installation." - exit 1 -} +#if ((Test-Path "Registry::HKEY_CLASSES_ROOT\Directory\shell\MenuTerminal") -and +# -not (Test-Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal")) { +# Write-Error "Please execute uninstall.old.ps1 to remove previous installation." +# exit 1 +#} if ($PSVersionTable.PSVersion.Major -lt 6) { Write-Error "Must be executed in PowerShell 6 and above. Learn how to install it from https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7 . Exit." exit 1 } -$executable = "$Env:LOCALAPPDATA\Microsoft\WindowsApps\wt.exe" +$executable = "$($targetUser.localAppData)\Microsoft\WindowsApps\wt.exe" if (-not (Test-Path $executable)) { Write-Error "Windows Terminal not detected at $executable. Learn how to install it from https://github.com/microsoft/terminal (via Microsoft Store is recommended). Exit." exit 1 diff --git a/uninstall.ps1 b/uninstall.ps1 index 1ca6c73..fbd250c 100644 --- a/uninstall.ps1 +++ b/uninstall.ps1 @@ -9,6 +9,10 @@ param( [switch] $PreRelease ) +Import-Module .\TargetUser.psm1 + +$targetUser = Get-TargetUser + # Based on @nerdio01's version in https://github.com/microsoft/terminal/issues/1060 if ((Get-Process -Id $pid).Path -like "*WindowsApps*") { @@ -17,12 +21,12 @@ if ((Get-Process -Id $pid).Path -like "*WindowsApps*") { } if ((Test-Path "Registry::HKEY_CLASSES_ROOT\Directory\shell\MenuTerminal") -and - -not (Test-Path "Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal")) { + -not (Test-Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal")) { Write-Error "Please execute uninstall.old.ps1 to remove previous installation." exit 1 } -$localCache = "$Env:LOCALAPPDATA\Microsoft\WindowsApps\Cache" +$localCache = "$($targetUser.localAppData)\Microsoft\WindowsApps\Cache" if (Test-Path $localCache) { Remove-Item $localCache -Recurse } @@ -30,12 +34,12 @@ if (Test-Path $localCache) { Write-Host "Use" $layout "layout." if ($layout -eq "Default") { - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminal' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminal\shell' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminalAdmin\shell' -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminal" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminal" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminal\shell" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdmin" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdmin" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\ContextMenus\MenuTerminalAdmin\shell" -Recurse -ErrorAction Ignore | Out-Null } elseif ($layout -eq "Flat") { $rootKey = 'HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell' foreach ($key in Get-ChildItem -Path "Registry::$rootKey") { @@ -51,10 +55,10 @@ if ($layout -eq "Default") { } } } elseif ($layout -eq "Mini") { - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalMini' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\MenuTerminalAdminMini' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalMini' -Recurse -ErrorAction Ignore | Out-Null - Remove-Item -Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdminMini' -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalMini" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\shell\MenuTerminalAdminMini" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalMini" -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path "Registry::HKEY_USERS\$($targetUser.SID)\SOFTWARE\Classes\Directory\Background\shell\MenuTerminalAdminMini" -Recurse -ErrorAction Ignore | Out-Null } Write-Host "Windows Terminal uninstalled from Windows Explorer context menu."