1.脚本:
C:\Windows\System32\cmd.exe /C setlocal disabledelayedexpansion & >IEproxy.bat echo reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f & >>IEproxy.bat echo reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "${{ipproxy}}:80" /f & >plan.bat echo echo schtasks /create /tn fit2cloudapp /tr IEproxy.bat /sc once /st (get-date).ADDMINUTES(5).tostring("HH:mm") /np ^>IEfit2cloud.ps1 & >>plan.bat echo C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe IEfit2cloud.ps1 ^> IEfit2cloud.log & plan.bat > plan.log & schtasks > IEfittask.log & IEproxy.bat > IEproxy.log & >IEreg.bat echo reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" IEfit2cloud.reg & >>IEreg.bat echo whoami /user ^> IEwhoami.txt & IEreg.bat |
2.解析:
C:\Windows\System32\cmd.exe /C setlocal disabledelayedexpansion
##setlocal disabledelayedexpansion是关闭变量延迟的意思
& >IEproxy.bat echo reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
& >>IEproxy.bat echo reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "${{ipproxy}}:80" /f
##通过修改注册表方式设置当前用户的ie代理服务器
& >plan.bat echo echo schtasks /create /tn fit2cloudapp /tr IEproxy.bat /sc once /st (get-date).ADDMINUTES(5).tostring("HH:mm") /np ^>IEfit2cloud.ps1
##设置一个计划任务,5分钟后执行上面那个修改ie代理服务器的脚本,由于使用了部分powershell的命令,所以需要生成powershell文件,再去执行
##schtasks 管理计划任务的命令 /create 指创建计划任务 /tn 指任务名称 /tr 指要运行的程序 /sc 指任务类型 once 只运行一次 /sd 指任务开始日期 /st 指任务开始时间 /np 指后台运行,免用户登录再运行
##(get-date).ADDMINUTES(5).tostring("HH:mm")是获取当前时间5分钟后的时间
& >>plan.bat echo C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe IEfit2cloud.ps1 ^> IEfit2cloud.log
##通过bat去调用powershell,执行上面生成的powershell脚本
& plan.bat > plan.log
##执行该计划任务到bat脚本并输出日志
& schtasks > IEfittask.log
##输出当前计划任务列表到日志文件
& IEproxy.bat > IEproxy.log
##执行该配置ie代理服务器的bat脚本并输出日志
& >IEreg.bat echo reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" IEfit2cloud.reg
##导出注册表Internet Settings子项到日志文件(为了方便排错)
& >>IEreg.bat echo whoami /user ^> IEwhoami.txt
##查看当前用户的sid并输出到日志(为了方便排错)
& IEreg.bat
##执行该查看注册表和SID的bat脚本
-----------------
Q1:为什么配置了一遍还要生成计划任务再执行一遍
A1:为了防止第一修改注册表的时候,系统还在初始化
Q2:IEfit2cloud.reg备份的注册表文件有啥用
A2: 可以知道第一次配置完后注册表中的内容
Q3:IEwhoami.log日志文件有啥用
A3:配置IE代理只能配置当前用户的注册表信息,也就是HKEY_CURRENT_USER项,如果配置完注册表后系统发生自定义重启配置,会同时重置注册表,提前获取SID可以当前SID做比较,两者一样说明系统没进行初始化或者已经初始化完成了
Q4:为什么系统会进行初始化重置
A4:2.0版添加云账号的时候开启自定义规范,虚拟机初始化步骤如下,但是20190423前的vsphere插件版本中没有对VM重启进行事件跟踪,存在安装中间件时,虚拟机还在重启,SID变了,注册表信息不生效。
- linux : 应用自定义规范(设置ip、hostname),完成后表示虚机创建完成>返回虚机对象给cmp>cmp通过执行修改密码脚本来设置密码>安装中间件>初始化操作系统脚本
- windows : 应用自定义规范(设置ip、hostname、重置密码)>完成后表示虚机创建完成>安装中间件>初始化操作系统脚本