From d5897343fbc9ef7136bbf29dcf55358a5cc540a0 Mon Sep 17 00:00:00 2001 From: Lightemerald Date: Wed, 11 Oct 2023 08:27:22 +0000 Subject: [PATCH] Update setupScriptInfo.ps1 --- setupScriptInfo.ps1 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/setupScriptInfo.ps1 b/setupScriptInfo.ps1 index b05f942..e39bf8f 100644 --- a/setupScriptInfo.ps1 +++ b/setupScriptInfo.ps1 @@ -114,8 +114,17 @@ if ($UserSID -ne $null -and $UserHKUPath -ne $null) { # Add entries to DisallowRun for cmd.exe and powershell.exe $DisallowRunKeyPath = "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun" - if (Test-Path -Path $DisallowRunKeyPath) { - Set-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "DisallowRun" -Value 1 + + if ((Test-Path -Path $DisallowRunKeyPath) -and (Get-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "DisallowRun").DisallowRun -eq 1) { + Write-Host "DisallowRun is already set to 1. Skipping the modification." + } else { + if (Test-Path -Path $DisallowRunKeyPath) { + Set-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "DisallowRun" -Value 1 + } else { + New-Item -Path $DisallowRunKeyPath -Force + Set-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "DisallowRun" -Value 1 + } + $applications = @("cmd.exe", "powershell.exe", "powershell_ise.exe") foreach ($valueName in $applications) { $valueExists = $DisallowRunKeyPath.PSObject.Properties.Name -contains $valueName @@ -123,13 +132,6 @@ if ($UserSID -ne $null -and $UserHKUPath -ne $null) { New-ItemProperty -Path $DisallowRunKeyPath -Name $valueName -Value $valueName -PropertyType String } } - } else { - New-Item -Path $DisallowRunKeyPath -Force - Set-ItemProperty -Path "$UserHKUPath\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "DisallowRun" -Value 1 - $applications = @("cmd.exe", "powershell.exe", "powershell_ise.exe") - foreach ($valueName in $applications) { - New-ItemProperty -Path $DisallowRunKeyPath -Name $valueName -Value $valueName -PropertyType String - } } } else { Write-Host "Unable to get the user's HKU registry."