批处理bat脚本修改hosts和配置环境变量

时间:2022-12-12 09:41:49

因为上班机每次重启都要初始化配置,所以需要配置开发所需要的环境变量和hosts文件

配置环境变量

新建bat文件,这边以添加maven环境变量为例,编辑代码:

::set system environment variable
setx PATH "‘原有的环境变量’+E:\maven\apache-maven-3.3.3\bin;" /m

echo "设置成功"
pause
exit



修改hosts文件

@echo off  
color 0F  
@attrib -r "%windir%\system32\drivers\etc\hosts"  
@echo ######测试配置 beg >>"%windir%\system32\drivers\etc\hosts"   
@echo 192.168.127.232       VAUTH-SERVER >>"%windir%\system32\drivers\etc\hosts"   
@echo 192.168.127.232       VCONTROLLER-SERVER >>"%windir%\system32\drivers\etc\hosts"  
@echo 192.168.127.232       SYSLOG-SERVER >>"%windir%\system32\drivers\etc\hosts"    
@echo ######测试配置 end >>"%windir%\system32\drivers\etc\hosts"   
@attrib +r "%windir%\system32\drivers\etc\hosts" 

echo "设置成功"
pause






将这两个bat文件放到开机启动项(开始->所有程序->启动)就可以了