【batch&powershell】解决IE相关网站兼容及显示、点击按钮无响应等问题方案
## 前言* 起因:财务无法点击登录进入保险网站做业务。
* 解决办法:运行保险网站提供的脚本。
* 产生的想法:
1. 利用保险网站提供的现成脚本,改写成适合公司内部自己用的IE站点设置脚本
2. 由此,必须根据网站地址,推测出兼容视图的hex。
这样的话,自己就能用现成脚本,结合相关的配置兼容视图站点代码,轻松应付很多IE站点出现的异常问题了。
## IE兼容性视图hex值测试
通过(https://chaoyuew.gitee.io/WPS-43-Advanced-Modifying-IE-Compatibility-View-Settings-with-Powershell.html)提供的源码,计算出网址的hex,通过如下指令植入注册表,添加兼容性视图站点是成立的。
```
reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData" /v "UserFilter" /t REG_BINARY /d
```
![](https://cdn.jsdelivr.net/gh/hoochanlon/scripts/AQUICK/catch2023-08-04%2020.29.31.png)
加入多个站点测试
!(https://cdn.jsdelivr.net/gh/hoochanlon/scripts/AQUICK/catch2023-08-04%2020.48.25.png)
## hex值需求分析
随时备着一份代码太麻烦了,要是能在线输入网址,并返回相应的hex结果就不错。或者
```powershell
irm https://ghproxy.com/https://raw.githubusercontent.com/hoochanlon/scripts/main/d-pwsh/clac_ie_clearablelistdata_hex.ps1|iex
```
!(https://cdn.jsdelivr.net/gh/hoochanlon/scripts/AQUICK/catch2023-08-04%2021.50.10.png)
### 附源码
### 生成兼容视图代码+hex值配套
对(https://chaoyuew.gitee.io/WPS-43-Advanced-Modifying-IE-Compatibility-View-Settings-with-Powershell.html)进行适应性改写,效果如上图。
代码地址:https://github.com/hoochanlon/scripts/blob/main/d-pwsh/clac_ie_clearablelistdata_hex.ps1
```
# 使用说明
# 下载到本地使用,需转成 GB2312 编码,否则中文乱码
Function Get-WebsiteHex(){
param(
$website
)
# 去除网址中的 https:// 和 http:// 前缀
$website = $website -replace "https?://", ""
# 去除斜杠后的所有内容
$website = $website -replace "/.*"
# 计算网站名称的十六进制长度
$hex_length = ::ToString(::GetBytes($website.length)).replace('-','')
# 将网站名称转换为十六进制数据
$hex_data = (::Unicode.GetBytes($website) | ForEach-Object { "{0:X2}" -f $_ }) -join ""
return "0C000000000000000000000101000000$hex_length$hex_data"
}
Function Get-IECompatibilityViewHexHeader(){
param(
]$websites
)
# 构建 IE 兼容性视图的头部
return ("411F00005308ADBA{0}FFFFFFFF01000000{0}" -f (::ToString(::GetBytes($websites.count)).replace('-','')))
}
Function Get-IECVHex(){
param(
$websites,
$ReturnBytes
)
# 获取每个网站的十六进制表示,并将它们连接起来
$siteArray = $websites -split "[, ]" | Where-Object { $_.Trim() -ne '' }
$hex_website = $siteArray | ForEach-Object { Get-WebsiteHex $_ }
$hex_result = ("411F00005308ADBA{0}FFFFFFFF01000000{0}$hex_website" -f ::ToString(::GetBytes($siteArray.count)).replace('-','')) -replace " "
if( $ReturnBytes ){
# 如果传入了 "-ReturnBytes" 开关,则返回字节数组
]$bytes = @()
for( $n=0; $n -lt $hex_result.length; $n += 2 ){
$bytes += (::ToInt64($hex_result.substring($n,2),16))
}
return $bytes
}else{
# 否则,返回十六进制字符串
return $hex_result
}
}
Write-Host ""
$websites = Read-Host "请输入想要IE兼容视图的网址"
# 从用户输入中获取网址并调用 Get-IECVHex 函数
Write-Host "`n 所有相关网址的hex值已生成,复制如下指令即可: `n"
Write-Host 'reg add "HKCU\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData" /v "UserFilter" /t REG_BINARY /d ' -NoNewline
Get-IECVHex -websites $websites
# 参考链接:
# * (https://chaoyuew.gitee.io/WPS-43-Advanced-Modifying-IE-Compatibility-View-Settings-with-Powershell.html)
# * (http://jeffgraves.me/2014/02/19/modifying-ie-compatibility-view-settings-with-powershell/)
# * (https://blog.csdn.net/thb_cn/article/details/125124565)
```
### IE兼容及显示、点击按钮无响应等问题处理
代码已去掉对保险官网的信任站点、兼容视图设置,方便自定义。
代码地址:https://github.com/hoochanlon/scripts/blob/main/d-bat/ie_web_setting_demo.bat
```
@SETLOCAL ENABLEDELAYEDEXPANSION
@ECHO OFF
@CLS
@ECHO ON
@ECHO 开始进行IE浏览器运行环境设置.......
@ECHO.&&ECHO.
@echo 设置IE8版本以上兼容性视图中显示所有网站
@rem 关于网站对应的hex值,情配合 clac_ie_clearablelistdata_hex.ps1 使用,这个例子是B站的hex值。
@reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData" /v UserFilter /t REG_BINARY /f /d 411F00005308ADBA01000000FFFFFFFF01000000010000000C00000000000000000000010100000010007700770077002E00620069006C006900620069006C0069002E0063006F006D00
@ECHO 正在添加受信任列表......()
@reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\baidu.com\www" /v http /t REG_DWORD /d 0x00000002 /f
@reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\10.10.10.1" /v http /t REG_DWORD /d 0x00000002 /f
@reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\192.168.1.1" /v http /t REG_DWORD /d 0x00000002 /f
@reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\192.168.1.2" /v http /t REG_DWORD /d 0x00000002 /f
@ECHO.&&ECHO 正在进行受信站点ActiveX权限设置......
@set RegPath=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1
@SET RegPath1=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
@SET RegPath2=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3
@REG ADD "%RegPath%" /V DisplayName /T REG_SZ /D "本地 Intranet" /F
@REG ADD "%RegPath%" /V Description /T REG_SZ /D "该区域中包含您公司 Intranet 上的所有网站。" /F
@echo 本地 Intranet区域设置
@REG ADD "%RegPath%" /V CurrentLevel /T REG_DWORD /D 0X0 /F
@REG add "%regpath%" /v "1001" /t reg_dword /d 0x00000001 /f
@REG add "%regpath%" /v "1004" /t reg_dword /d 0x00000001 /f
@reg add "%regpath%" /v "1200" /d "0" /t REG_DWORD /f
@REG add "%regpath%" /v "120B" /t reg_dword /d 0x00000003 /f
@REG add "%regpath%" /v "1201" /t reg_dword /d 0x00000001 /f
@reg add "%regpath%" /v "1208" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /v "1209" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /v "1400" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /v "1402" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /v "1407" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /v "1405" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /v "1609" /d "0" /t REG_DWORD /f
@REG add "%regpath%" /v "1804" /t reg_dword /d 0x00000001 /f
@REG add "%regpath%" /v "1809" /t reg_dword /d 0x00000000 /f
@reg add "%regpath%" /v "2300" /d "0" /t REG_DWORD /f
@reg add "%regpath%" /V "2201" /d "0" /t REG_DWORD /f
@echo 受信任的站点区域
@REG ADD "%RegPath1%" /V CurrentLevel /T REG_DWORD /D 0X0 /F
@REG add "%regpath1%" /v "1001" /t reg_dword /d 0x00000001 /f
@REG add "%regpath1%" /v "1004" /t reg_dword /d 0x00000001 /f
@reg add "%regpath1%" /v "1200" /d "0" /t REG_DWORD /f
@REG add "%regpath1%" /v "120B" /t reg_dword /d 0x00000003 /f
@REG add "%regpath1%" /v "1201" /t reg_dword /d 0x00000001 /f
@reg add "%regpath1%" /v "1208" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /v "1209" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /v "1400" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /v "1402" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /v "1405" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /v "1407" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /v "1609" /d "0" /t REG_DWORD /f
@REG add "%regpath1%" /v "1804" /t reg_dword /d 0x00000001 /f
@REG add "%regpath1%" /v "1809" /t reg_dword /d 0x00000000 /f
@reg add "%regpath1%" /v "2300" /d "0" /t REG_DWORD /f
@reg add "%regpath1%" /V "2201" /d "0" /t REG_DWORD /f
@echo Internet 区域设置
@REG ADD "%RegPath2%" /V CurrentLevel /T REG_DWORD /D 0X0 /F
@REG add "%regpath2%" /v "1001" /t reg_dword /d 0x00000001 /f
@REG add "%regpath2%" /v "1004" /t reg_dword /d 0x00000001 /f
@reg add "%regpath2%" /v "1200" /d "0" /t REG_DWORD /f
@REG add "%regpath2%" /v "1201" /t reg_dword /d 0x00000001 /f
@reg add "%regpath2%" /v "1208" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /v "1209" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /v "1400" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /v "1402" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /v "1405" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /v "1407" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /v "1609" /d "0" /t REG_DWORD /f
@REG add "%regpath2%" /v "1804" /t reg_dword /d 0x00000001 /f
@REG add "%regpath2%" /v "1809" /t reg_dword /d 0x00000000 /f
@reg add "%regpath2%" /v "2300" /d "0" /t REG_DWORD /f
@reg add "%regpath2%" /V "2201" /d "0" /t REG_DWORD /f
@REG ADD "%RegPath%" /V Description /T REG_SZ /D "该区域中包含所有未放在其他区域中的网站" /F
@REG ADD "%RegPath%4" /V DisplayName /T REG_SZ /D "受限站点" /F
@REG ADD "%RegPath%4" /V Description /T REG_SZ /D "该区域中包含可能会损坏您的计算机或数据的网站。"" /F
@ECHO ActiveX权限设置完成
@echo. && @echo 去掉IE弹窗提醒...
@reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\New Windows" /v "PopupMgr" /d "0" /t REG_DWORD /f
@ECHO.&&ECHO 正在重启IE浏览器,请稍等......
::TASKKILL /IM iexplore.exe /T /F
@TASKKILL /IM iexplore.exe /F
@PING 127.0.0.1 -4 -n 5 >nul
@ECHO.&&ECHO.&&@ECHO IE使用环境配置完成。
@PING 127.0.0.1 -4 -n 5 >nul
EXIT
```
### 参考资料
* (https://chaoyuew.gitee.io/WPS-43-Advanced-Modifying-IE-Compatibility-View-Settings-with-Powershell.html)
* (http://jeffgraves.me/2014/02/19/modifying-ie-compatibility-view-settings-with-powershell/)
* (https://blog.csdn.net/thb_cn/article/details/125124565)
页:
[1]