在AWS上使用PowerShell在Packer中禁用Internet Explorer增强安全配置失败

4

我正在尝试使用PowerShell在Packer上禁用Internet Explorer增强安全配置,从AWS构建Windows Server 2016实例时,使用最新的AMI。

我从packer provisioners中调用以下PS函数:

function Disable-InternetExplorerESC {
   $AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
   $UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
   Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
   Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
   Stop-Process -Name Explorer -Force -ErrorAction Continue
   Write-Host "IE Enhanced Security Configuration (ESC) has been disabled."
}

Disable-InternetExplorerESC

然而,Stop-Process -Name Explorer -Force 抛出以下错误: Stop-Process : 找不到名称为“Explorer”的进程。请验证进程名称并重新调用 cmdlet。 远程登录到服务器并打开 Server Manager 并检查本地服务器设置,发现 IE 增强安全配置为“关闭”,但打开 Internet Explorer 仍显示设置为“开启”,并阻止下载。我尝试在更改后重启机器,但该设置仍处于模糊状态。是否有其他关闭 IE ESC 的方法可以尝试或者在 Packer 中处理此问题的另一种方法?
2个回答

5

我能够使用以下PowerShell脚本作为Packer构建脚本中的高级权限供应商来使其工作:

function Disable-InternetExplorerESC {
   $AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
   $UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
   Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
   Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
   Rundll32 iesetup.dll, IEHardenLMSettings
   Rundll32 iesetup.dll, IEHardenUser
   Rundll32 iesetup.dll, IEHardenAdmin
   Write-Host "IE Enhanced Security Configuration (ESC) has been disabled."
}

Disable-InternetExplorerESC

这是用于提供程序的Packer代码片段:
{
   "type": "powershell",
   "scripts":[
   "{{ template_dir }}/scripts/Disable-InternetExplorerESC.ps1"
   ],
   "elevated_user": "{{user `local_admin`}}",
   "elevated_password": "{{user `local_admin_password`}}"
}

此外,这似乎只是为那些运行脚本的高级用户禁用IE ESC功能。

0
另一种方法(不使用PowerShell)是使用服务器管理器关闭IE增强安全性。我发布这个答案,因为在搜索“如何在AWS中关闭IE增强安全配置”时,这是第一个弹出的答案。
打开服务器管理器>本地服务器>查找IE增强安全配置>通过单击“打开”来关闭它(您只能将其关闭给管理员或所有用户)
或者如果您只能访问PowerShell,则可以运行以下脚本
禁用管理员的IE ESC
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
New-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -PropertyType DWord
禁用用户的 IE ESC
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1AA-37EF-4b3f-8CFC-4F3A74704073}"
New-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -PropertyType DWord

当您希望通过PowerShell运行某些内容时,如何进行“点击”操作呢? - Steven K7FAQ
@StevenK7FAQ 请查看答案中的注释。这是当有人进行谷歌搜索 - 如何关闭IE增强安全配置时,首先出现的答案。我们在这里帮助需要帮助的人。 - codeslord

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接