运行 脚本时的安全警告 - 取消阻止文件未取消阻止文件
Security Warning when running scripts - Unblock-File not unblocking file
当 运行 在我的计算机上运行任何脚本时,我突然开始收到此警告:
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer...
截图:
文件未被阻止。
我有
- 已在文件资源管理器 > 属性中检查。
- 也使用
Unblock-File
cmdlet 解除阻止。
- 使用 cmdlet 检查流:
Get-Content -Path '\Path\Script.ps1' -Stream Zone.Identifier
。找不到流。
- 使用了来自 Sysinternals 的 Streams.exe:
streams.exe -d \Path\Script.ps1
。未找到包含流的文件。
还尝试使用 Powershell 删除流:
Remove-Item -Path \Path\Script.ps1 -Stream Zone.Identifier
当然没有成功,因为没有流。
执行策略不受限制。
当我 运行 Set-ExecutionPolicy Bypass 时,它会在没有警告的情况下运行。
但是,它应该在不受限制时也能正常工作。
老实说,我不知道发生了什么。
LGPE > gpedit.msc
Computer Configuration > Administrative Templates, > Windows Components, > Internet Explorer>expand Internet Control Panel.
Security Page > Intranet Sites: Include all local (intranet) sites not listed in other zones, and then click Properties.
Click Enabled.
Turn on automatic detection of the intranet, and then click Properties.
Click Disabled, and then click OK.
或注册表
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\"UNCAsIntranet" = "0"
默认情况下,PS 不允许脚本在系统 ENV 上 运行。
您需要将策略设置为不受限制或远程签名
采用:
Set-ExecutionPolicy Remotesigned
要么
Set-ExecutionPolicy Unrestricted
打开 PS 控制台并键入此内容并按回车键,然后尝试 运行 运行您的脚本。
搜索后我发现有人有类似的问题,并解释说经典 UNC 路径可以在不提示取消阻止文件的情况下工作:
\Servername\Path...
但是 FQDN 路径在默认情况下不被视为安全并且会提示:
\Servername.foo.local\Path...
我自己的测试证实这是正确的,因为从路径中删除 .foo.local
会导致 Unblock-File
提示停止。
将所有本地站点视为 Intranet 区域的一部分的正确注册表项、名称和值是:
Keys:
HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap
HKCU\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap
Name: IntranetName
Type: DWORD
Value: 1
您可以通过 PowerShell 为本地计算机设置此项(在提升的提示中),如下所示:
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap" -Name "IntranetName" -Type DWord -Value 1
有关组策略的详细信息,请参阅Intranet Sites: Include all local (intranet) sites not listed in other zones。
当 运行 在我的计算机上运行任何脚本时,我突然开始收到此警告:
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer...
截图:
文件未被阻止。
我有
- 已在文件资源管理器 > 属性中检查。
- 也使用
Unblock-File
cmdlet 解除阻止。 - 使用 cmdlet 检查流:
Get-Content -Path '\Path\Script.ps1' -Stream Zone.Identifier
。找不到流。 - 使用了来自 Sysinternals 的 Streams.exe:
streams.exe -d \Path\Script.ps1
。未找到包含流的文件。
还尝试使用 Powershell 删除流:
Remove-Item -Path \Path\Script.ps1 -Stream Zone.Identifier
当然没有成功,因为没有流。
执行策略不受限制。
当我 运行 Set-ExecutionPolicy Bypass 时,它会在没有警告的情况下运行。 但是,它应该在不受限制时也能正常工作。
老实说,我不知道发生了什么。
LGPE > gpedit.msc
Computer Configuration > Administrative Templates, > Windows Components, > Internet Explorer>expand Internet Control Panel. Security Page > Intranet Sites: Include all local (intranet) sites not listed in other zones, and then click Properties. Click Enabled.
Turn on automatic detection of the intranet, and then click Properties. Click Disabled, and then click OK.
或注册表
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\"UNCAsIntranet" = "0"
PS 不允许脚本在系统 ENV 上 运行。 您需要将策略设置为不受限制或远程签名 采用: Set-ExecutionPolicy Remotesigned 要么 Set-ExecutionPolicy Unrestricted
打开 PS 控制台并键入此内容并按回车键,然后尝试 运行 运行您的脚本。
搜索后我发现有人有类似的问题,并解释说经典 UNC 路径可以在不提示取消阻止文件的情况下工作:
\Servername\Path...
但是 FQDN 路径在默认情况下不被视为安全并且会提示:
\Servername.foo.local\Path...
我自己的测试证实这是正确的,因为从路径中删除 .foo.local
会导致 Unblock-File
提示停止。
将所有本地站点视为 Intranet 区域的一部分的正确注册表项、名称和值是:
Keys:
HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap
HKCU\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap
Name: IntranetName
Type: DWORD
Value: 1
您可以通过 PowerShell 为本地计算机设置此项(在提升的提示中),如下所示:
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap" -Name "IntranetName" -Type DWord -Value 1
有关组策略的详细信息,请参阅Intranet Sites: Include all local (intranet) sites not listed in other zones。