使用VBS脚本对INTERNET 属性进行设置
另附:INTERNET属性快速打开方法 WIN+R - inetcpl.cpl
本脚本通过赋值reg_Path变量,通过修改USER注册表对用户INTERNET设置进行修改,因此脚本需以User权限运行且仅针对当前User生效。
注册表项也可使用组策略进行全员部署或组策略设立登录脚本运行,去除MessageBOX
简易版:
使用自动配置脚本如下(PAC文件):
Dim g_wshShell: Set g_wshShell = WScript.CreateObject("WScript.Shell")
Dim reg_Path
Dim msg
On Error Resume Next
::以下代码即使出错也会继续执行,结果使用err.number来判断 =0表示成功
'使用自动配置脚本
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\AutoConfigURL"
g_wshShell.RegWrite reg_Path, "<PAC文件>", "REG_SZ"
If Err.Number = 0 Then
msg= "IE PAC setting completed."
Else
msg="IE PAC Setting failed."
End If
MsgBox(msg)
高级版:
Option Explicit
On Error Resume Next
'定义代理服务器及端口,主页
Dim proxyserver, startpage
proxyserver = "<ProxyServer>:<Port>"
startpage = "about:blank"
'定义变量缩写
Dim g_wshShell: Set g_wshShell = WScript.CreateObject("WScript.Shell")
Dim g_fso: Set g_fso = CreateObject("Scripting.FileSystemObject")
'定义日志输出路径变量
Dim myFolder, logName, logFile
myFolder = "D:\temp\"
logName = "IESetting.log"
logFile = myFolder & logName
'定义返回值变量
Dim result_IESettings
result_IESettings = false
'主程序
Call WriteLog(logFile, "Start process...")
On Error Resume Next: Err.Clear
'检测日志文件,不存在则创建
If g_fso.FolderExists(myFolder)= False Then
CreateFolder(myFolder)
End If
Call IESettings()
Dim msg
'判断返回值
If (result_IESettings = false) Then
msg = "Opertaion successful Failed!"
Else
msg = "Opertaion successful completed!"
End If
MsgBox(msg)
'--------+---------+---------+---------+---------+---------+---------+---------+
' WriteLog
'--------+---------+---------+---------+---------+---------+---------+---------+
Private Sub WriteLog(ByVal logPass, ByVal logString)
On Error Resume Next
Dim logFile: Set logFile = g_fso.OpenTextFile(logPass, 8, True)
Dim yyyymmdd: yyyymmdd = year(Now()) & Right(0 & month(Now()), 2) & Right(0 & day(Now()), 2)
Dim hhmmss: hhmmss = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
logFile.Write "[" & yyyymmdd & ":" & hhmmss & "] " & logString & vbCrLf
logFile.Close
Set logFile = Nothing
On Error GoTo 0
End Sub
'--------+---------+---------+---------+---------+---------+---------+---------+
' IE Settings
'--------+---------+---------+---------+---------+---------+---------+---------+
Private Sub IESettings()
On Error Resume Next: Err.Clear
Dim reg_Path
'主页
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page"
g_wshShell.RegWrite reg_Path, startpage, "REG_SZ"
'代理服务器
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
g_wshShell.RegWrite reg_Path, proxyserver, "REG_SZ"
'启用代理
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
g_wshShell.RegWrite reg_Path, 1 ,"REG_DWORD"
'Proxy例外
reg_Path = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride"
g_wshShell.RegWrite reg_Path, "URL1;URL2", "REG_SZ"
'常规 -> 设置 -> Internet临时文件 -> 检查所存网页的较新版本
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\SyncMode5"
g_wshShell.RegWrite reg_Path, 3, "REG_DWORD"
'可信站点 -> 自定义级别 ->对未标记为可安全执行脚本的ActiveX控件初始化和执行脚本
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2\1201"
g_wshShell.RegWrite reg_Path, 0, "REG_DWORD"
'可信站点 -> 自定义级别 ->活动脚本
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2\1400"
g_wshShell.RegWrite reg_Path, 0, "REG_DWORD"
'可信站点 -> 自定义级别 ->使用弹出窗口阻止程序
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2\1809"
g_wshShell.RegWrite reg_Path, 3, "REG_DWORD"
'高级 -> 打印背景颜色和图像
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\Print_Background"
g_wshShell.RegWrite reg_Path, "yes", "REG_SZ"
'高级 -> 启用自动图像大小调整
reg_Path = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\Enable AutoImageResize"
g_wshShell.RegWrite reg_Path, "no", "REG_SZ"
'IE 站点设置
reg_Path = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\"
'Add Local Intranet Sites 本地Intranet站点
g_wshShell.RegWrite reg_Path & "URL3",1,"REG_DWORD"
'Add Trusted Sites 受信任的站点
g_wshShell.RegWrite reg_Path & "URL4",2,"REG_DWORD"
'Add Internet Sites Internet的站点
g_wshShell.RegWrite reg_Path & "URL5",3,"REG_DWORD"
'Add Restricted Sites 受限制的站点
g_wshShell.RegWrite reg_Path & "URL6",4,"REG_DWORD"
'write log
If Err.Number = 0 Then
Call WriteLog(logFile, "IE setting completed.")
result_IESettings = true
Else
Call WriteLog(logFile, "IE Setting failed." & Err.Number & " " & Err.Description)
result_IESettings = false
End If
End Sub
详细注册表路径及参数参阅微软文档:
https://docs.microsoft.com/zh-cn/troubleshoot/browsers/ie-security-zones-registry-entries