mirror of
https://github.com/zoicware/RemoveWindowsAI.git
synced 2025-12-17 15:16:27 +01:00
fix error when executionpolicy is set via settings page fix #54
This commit is contained in:
@@ -961,10 +961,20 @@ foreach ($choice in $aipackages) {
|
|||||||
Set-ExecutionPolicy Unrestricted -Force -ErrorAction Stop
|
Set-ExecutionPolicy Unrestricted -Force -ErrorAction Stop
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
#user has set powershell execution policy via group policy, to change it we need to update the registry
|
#user has set powershell execution policy via group policy or via settings, to change it we need to update the registry
|
||||||
$Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell' -Name 'ExecutionPolicy' -ErrorAction SilentlyContinue
|
try {
|
||||||
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'EnableScripts' /t REG_DWORD /d '1' /f >$null
|
$Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell' -Name 'ExecutionPolicy' -ErrorAction Stop
|
||||||
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
|
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'EnableScripts' /t REG_DWORD /d '1' /f >$null
|
||||||
|
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
|
||||||
|
$Global:executionPolicyUser = $false
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$Global:executionPolicyUser = $true
|
||||||
|
$Global:ogExecutionPolicy = Get-ItemPropertyValue -Path 'HKCU:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' -Name 'ExecutionPolicy'
|
||||||
|
Reg.exe add 'HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d 'Unrestricted' /f >$null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2228,7 +2238,12 @@ else {
|
|||||||
|
|
||||||
#set executionpolicy back to what it was
|
#set executionpolicy back to what it was
|
||||||
if ($ogExecutionPolicy) {
|
if ($ogExecutionPolicy) {
|
||||||
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
|
if ($Global:executionPolicyUser) {
|
||||||
|
Reg.exe add 'HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Restart-Computer -Force
|
Restart-Computer -Force
|
||||||
}
|
}
|
||||||
@@ -2272,7 +2287,12 @@ catch {}
|
|||||||
|
|
||||||
#set executionpolicy back to what it was
|
#set executionpolicy back to what it was
|
||||||
if ($ogExecutionPolicy) {
|
if ($ogExecutionPolicy) {
|
||||||
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
|
if ($Global:executionPolicyUser) {
|
||||||
|
Reg.exe add 'HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Reg.exe add 'HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell' /v 'ExecutionPolicy' /t REG_SZ /d $ogExecutionPolicy /f >$null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$nonInteractive) {
|
if (!$nonInteractive) {
|
||||||
|
|||||||
Reference in New Issue
Block a user