Show error if powershell functionality is restricted (#79)

This commit is contained in:
Raphire
2024-06-26 20:27:25 +02:00
parent d19f20fbf9
commit 589f2e82df
2 changed files with 21 additions and 2 deletions

View File

@@ -35,6 +35,15 @@ param (
[switch]$DisableShare, [switch]$HideShare [switch]$DisableShare, [switch]$HideShare
) )
# Show error if current powershell environment does not have LanguageMode set to FullLanguage
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
Write-Host "Error: Win11Debloat is unable to run on your system. Powershell execution is restricted by security policies" -ForegroundColor Red
Write-Output ""
Write-Output "Press enter to exit..."
Read-Host | Out-Null
Exit
}
Clear-Host Clear-Host
Write-Output "-------------------------------------------------------------------------------------------" Write-Output "-------------------------------------------------------------------------------------------"
Write-Output " Win11Debloat Script - Get" Write-Output " Win11Debloat Script - Get"

View File

@@ -39,6 +39,16 @@ param (
) )
# Show error if current powershell environment does not have LanguageMode set to FullLanguage
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
Write-Host "Error: Win11Debloat is unable to run on your system. Powershell execution is restricted by security policies" -ForegroundColor Red
Write-Output ""
Write-Output "Press enter to exit..."
Read-Host | Out-Null
Exit
}
# Shows application selection form that allows the user to select what apps they want to remove or keep # Shows application selection form that allows the user to select what apps they want to remove or keep
function ShowAppSelectionForm { function ShowAppSelectionForm {
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
@@ -525,7 +535,7 @@ else {
Write-Warning "Winget is not installed or outdated. This may prevent Win11Debloat from removing certain apps." Write-Warning "Winget is not installed or outdated. This may prevent Win11Debloat from removing certain apps."
Write-Output "" Write-Output ""
Write-Output "Press any key to continue anyway..." Write-Output "Press any key to continue anyway..."
Read-Host | Out-Null $null = [System.Console]::ReadKey()
} }
} }
@@ -607,7 +617,7 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPP
Write-Output "" Write-Output ""
Write-Output "Press any key to go back..." Write-Output "Press any key to go back..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") $null = [System.Console]::ReadKey()
} }
elseif (($Mode -eq '4')-and -not (Test-Path "$PSScriptRoot/SavedSettings")) { elseif (($Mode -eq '4')-and -not (Test-Path "$PSScriptRoot/SavedSettings")) {
$Mode = $null $Mode = $null