前几天在完成了TMG_×××的配置后,一直在想能否更简化用户的操作呢?最好是通过脚本的方式让用户不用做任何配置,只需点击就可以完成对所有×××的配置,经过一段时间的编写和修改后,今天晚上终于完成了Window XP下×××自动配置的脚本,以前没怎么写过,第一次写,遇到了不少问题,不过经过自己的修改后已经完成了如下功能:
1、自动创建所有×××服务器。
2、创建所有×××服务器对应的桌面快捷方式。
3、生成PBK文件的快捷方式。
4、对已有×××连接进行校对,判断是否已经有过配置操作。
5、配置完成后,根据用户输入的值判断是否重新启动。
当然在配置过程中,可能与Windows 7上实现×××自动配置还是有一些区别的,区别之处主要在于像路径选择是Windows XP没有办法识别文件夹名中带有空格的名称,这时可能就需要对这些有空格的文件夹名称以引号的方式进行设置了,具体的大家可以看看后边的配置,写得可能也不是最精简的,但是还是想分享一下,让更多的朋友在遇到同样的问题时,可以参考一下,呵呵。
@echo off & color 5a
echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo ×××连接自动配置连接
echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo 配置过程中,请勿进行任何操作,以保证配置顺利完成!
echo.
echo. 祝您工作愉快、顺利!
echo.
echo 确认安装配置×××请按任意键继续!
pause
cls
@echo off
echo 正在检查×××1.test.com是否存在,请稍等……
@echo off
ping 127.0.0.1 -n 10>nul
find "×××1.test.com" "%AllUSERSPROFILE%\Application Data"\Microsoft\Network\Connections\Pbk\rasphone.pbk && goto :×××2.test.com || goto :add×××1.test.com
:×××2.test.com
@echo off
cls
echo ×××1.test.com已经存在或创建完成!
cls
echo 正在检查×××2.test.com是否存在,请稍等……
@echo off
ping 127.0.0.1 -n 10>nul
find "×××2.test.com" "%AllUSERSPROFILE%\Application Data"\Microsoft\Network\Connections\Pbk\rasphone.pbk && goto :×××3.test.com || goto :add×××2.test.com
:×××3.test.com
@echo off
cls
echo ×××2.test.com已经存在或创建完成!
cls
echo 正在检查×××3.test.com是否存在,请稍等……
@echo off
ping 127.0.0.1 -n 10>nul
find "×××3.test.com" "%AllUSERSPROFILE%\Application Data"\Microsoft\Network\Connections\Pbk\rasphone.pbk && goto :no || goto :add×××3.test.com
pause
:add×××1.test.com
@echo off
echo 正在检查×××1.test.com是否存在,请稍等……
@echo off
ping 127.0.0.1 -n 10>nul
find "×××1.test.com" "%AllUSERSPROFILE%\Application Data"\Microsoft\Network\Connections\Pbk\rasphone.pbk && goto :×××2.test.com || goto :add×××1.test.com
:×××2.test.com
@echo off
cls
echo ×××1.test.com已经存在或创建完成!
cls
echo 正在检查×××2.test.com是否存在,请稍等……
@echo off
ping 127.0.0.1 -n 10>nul
find "×××2.test.com" "%AllUSERSPROFILE%\Application Data"\Microsoft\Network\Connections\Pbk\rasphone.pbk && goto :×××3.test.com || goto :add×××2.test.com
:×××3.test.com
@echo off
cls
echo ×××2.test.com已经存在或创建完成!
cls
echo 正在检查×××3.test.com是否存在,请稍等……
@echo off
ping 127.0.0.1 -n 10>nul
find "×××3.test.com" "%AllUSERSPROFILE%\Application Data"\Microsoft\Network\Connections\Pbk\rasphone.pbk && goto :no || goto :add×××3.test.com
pause
:add×××1.test.com
@echo off
echo 正在创建×××1.test.com连接,请稍等……
echo set WshShell = CreateObject("WScript.Shell") >TEST_×××.VBS
echo WshShell.Run "Rasphone -a" >> TEST_×××.VBS
echo WScript.Sleep 500 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+T" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××1.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××1.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "{ENTER} >> TEST_×××.VBS
start TEST_×××.VBS
cls
echo 正在完成×××1.test.com_×××连接配置,请稍等!
ping 127.0.0.1 -n 10>nul
cls
echo ×××1.test.com连接创建完成,即将为您创建×××1.test.com桌面快捷方式,请稍等……
ping 127.0.0.1 -n 10>nul
(echo set ws=createobject("wscript.shell"^)
echo 正在创建×××1.test.com连接,请稍等……
echo set WshShell = CreateObject("WScript.Shell") >TEST_×××.VBS
echo WshShell.Run "Rasphone -a" >> TEST_×××.VBS
echo WScript.Sleep 500 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+T" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××1.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××1.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "{ENTER} >> TEST_×××.VBS
start TEST_×××.VBS
cls
echo 正在完成×××1.test.com_×××连接配置,请稍等!
ping 127.0.0.1 -n 10>nul
cls
echo ×××1.test.com连接创建完成,即将为您创建×××1.test.com桌面快捷方式,请稍等……
ping 127.0.0.1 -n 10>nul
(echo set ws=createobject("wscript.shell"^)
echo ws.run "cmd /c ncpa.cpl",0
echo wscript.sleep 1000
echo ws.sendkeys "{f5}"
echo wscript.sleep 1000
echo ws.sendkeys "×××1.test.com"
echo wscript.sleep 500
echo ws.sendkeys "%%{f}"
echo wscript.sleep 500
echo ws.sendkeys "{s}"
echo wscript.sleep 300
echo ws.sendkeys "{y}"
echo wscript.sleep 300
echo ws.sendkeys "%%{f4}")>%temp%\TEST_×××.vbs
start /wait %temp%\TEST_×××.vbs
cls
echo ×××1.test.com桌面快捷方式创建完成,即将为您配置×××2.test.com连接,请稍等……
ping 127.0.0.1 -n 10>nul
goto:×××2.test.com
:add×××2.test.com
echo 正在创建×××2.test.com连接,请稍等……
echo set WshShell = CreateObject("WScript.Shell") >TEST_×××.VBS
echo WshShell.Run "Rasphone -a" >>TEST_×××.VBS
echo WScript.Sleep 500 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+T" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××2.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××2.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "{ENTER}" >> TEST_×××.VBS
start TEST_×××.VBS
cls
echo 正在完成×××2.test.com_×××连接配置,请稍等!
ping 127.0.0.1 -n 10>nul
cls
echo ×××2.test.com连接创建完成,即将为您创建×××2.test.com桌面快捷方式,请稍等……
ping 127.0.0.1 -n 10>nul
(echo set ws=createobject("wscript.shell"^)
cls
echo ×××1.test.com桌面快捷方式创建完成,即将为您配置×××2.test.com连接,请稍等……
ping 127.0.0.1 -n 10>nul
goto:×××2.test.com
:add×××2.test.com
echo 正在创建×××2.test.com连接,请稍等……
echo set WshShell = CreateObject("WScript.Shell") >TEST_×××.VBS
echo WshShell.Run "Rasphone -a" >>TEST_×××.VBS
echo WScript.Sleep 500 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+T" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××2.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××2.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "{ENTER}" >> TEST_×××.VBS
start TEST_×××.VBS
cls
echo 正在完成×××2.test.com_×××连接配置,请稍等!
ping 127.0.0.1 -n 10>nul
cls
echo ×××2.test.com连接创建完成,即将为您创建×××2.test.com桌面快捷方式,请稍等……
ping 127.0.0.1 -n 10>nul
(echo set ws=createobject("wscript.shell"^)
echo ws.run "cmd /c ncpa.cpl",0
echo wscript.sleep 1000
echo ws.sendkeys "{f5}"
echo wscript.sleep 1000
echo ws.sendkeys "×××2.test.com"
echo wscript.sleep 500
echo ws.sendkeys "%%{f}"
echo wscript.sleep 500
echo ws.sendkeys "{s}"
echo wscript.sleep 300
echo ws.sendkeys "{y}"
echo wscript.sleep 300
echo ws.sendkeys "%%{f4}")>%temp%\TEST_×××.vbs
start /wait %temp%\TEST_×××.vbs
cls
echo ×××2.test.com桌面快捷方式创建完成,即将为您配置×××3.test.com连接,请稍等……
ping 127.0.0.1 -n 10>nul
goto:×××3.test.com
:add×××3.test.com
echo 正在创建×××3.test.com连接,请稍等……
echo set WshShell = CreateObject("WScript.Shell") >TEST_×××.VBS
echo WshShell.Run "Rasphone -a" >>TEST_×××.VBS
echo WScript.Sleep 500 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+T" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××3.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××3.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "{ENTER}" >> TEST_×××.VBS
start TEST_×××.VBS
cls
echo 正在完成×××3.test.com_×××连接配置,请稍等!
ping 127.0.0.1 -n 10>nul
cls
echo ×××3.test.com连接创建完成,即将为您创建×××3.test.com桌面快捷方式,请稍等……
ping 127.0.0.1 -n 10>nul
(echo set ws=createobject("wscript.shell"^)
echo ×××2.test.com桌面快捷方式创建完成,即将为您配置×××3.test.com连接,请稍等……
ping 127.0.0.1 -n 10>nul
goto:×××3.test.com
:add×××3.test.com
echo 正在创建×××3.test.com连接,请稍等……
echo set WshShell = CreateObject("WScript.Shell") >TEST_×××.VBS
echo WshShell.Run "Rasphone -a" >>TEST_×××.VBS
echo WScript.Sleep 500 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+T" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××3.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "%%+N" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "×××3.test.com" >>TEST_×××.VBS
echo WScript.Sleep 100 >> TEST_×××.VBS
echo WshShell.SendKeys "{ENTER}" >> TEST_×××.VBS
start TEST_×××.VBS
cls
echo 正在完成×××3.test.com_×××连接配置,请稍等!
ping 127.0.0.1 -n 10>nul
cls
echo ×××3.test.com连接创建完成,即将为您创建×××3.test.com桌面快捷方式,请稍等……
ping 127.0.0.1 -n 10>nul
(echo set ws=createobject("wscript.shell"^)
echo ws.run "cmd /c ncpa.cpl",0
echo wscript.sleep 1000
echo ws.sendkeys "{f5}"
echo wscript.sleep 1000
echo ws.sendkeys "×××3.test.com"
echo wscript.sleep 500
echo ws.sendkeys "%%{f}"
echo wscript.sleep 500
echo ws.sendkeys "{s}"
echo wscript.sleep 300
echo ws.sendkeys "{y}"
echo wscript.sleep 300
echo ws.sendkeys "%%{f4}")>%temp%\TEST_×××.vbs
start /wait %temp%\TEST_×××.vbs
cls
echo ×××3.test.com桌面快捷方式创建完成.
del TEST_×××.VBS
ping 127.0.0.1 -n 10>nul
cls
goto:check_***
:check_***
echo 即将对配置×××进连接行校对,请稍后……
@echo off
ping 127.0.0.1 -n 10>nul
echo ×××1.test.com 配置校对完成!
@echo off
ping 127.0.0.1 -n 10>nul
echo ×××2.test.com 配置校对完成!
@echo off
ping 127.0.0.1 -n 10>nul
echo ×××3.test.com 配置校对完成!
ping 127.0.0.1 -n 10>nul
goto:creat_pbk
:creat_pbk
echo 即将为您生成TEST_×××.PBK桌面文件
@echo off
ping 127.0.0.1 -n 10>nul
for /f "delims=" %%i in ("Set ws=WScript.CreateObject("wscript.shell")") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("strdesktop=ws.SpecialFolders("desktop")") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("Set path=ws.CreateShortcut(strdesktop & "\TEST_×××.lnk")") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("path.targetpath="%AllUSERSPROFILE%\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk"") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("path.save") do echo %%i >> TEST_×××.vbs
cscript TEST_×××.vbs & del TEST_×××.vbs
@echo off
ping 127.0.0.1 -n 10>nul
del TEST_×××.vbs
echo ×××3.test.com桌面快捷方式创建完成.
del TEST_×××.VBS
ping 127.0.0.1 -n 10>nul
cls
goto:check_***
:check_***
echo 即将对配置×××进连接行校对,请稍后……
@echo off
ping 127.0.0.1 -n 10>nul
echo ×××1.test.com 配置校对完成!
@echo off
ping 127.0.0.1 -n 10>nul
echo ×××2.test.com 配置校对完成!
@echo off
ping 127.0.0.1 -n 10>nul
echo ×××3.test.com 配置校对完成!
ping 127.0.0.1 -n 10>nul
goto:creat_pbk
:creat_pbk
echo 即将为您生成TEST_×××.PBK桌面文件
@echo off
ping 127.0.0.1 -n 10>nul
for /f "delims=" %%i in ("Set ws=WScript.CreateObject("wscript.shell")") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("strdesktop=ws.SpecialFolders("desktop")") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("Set path=ws.CreateShortcut(strdesktop & "\TEST_×××.lnk")") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("path.targetpath="%AllUSERSPROFILE%\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk"") do echo %%i >> TEST_×××.vbs
for /f "delims=" %%i in ("path.save") do echo %%i >> TEST_×××.vbs
cscript TEST_×××.vbs & del TEST_×××.vbs
@echo off
ping 127.0.0.1 -n 10>nul
del TEST_×××.vbs
echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo 感谢您的耐心等待,×××配置完成
echo 现在您可以使用配置好的任意一个做为连接点使用×××
echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo 感谢您的使用!
@echo off
set /p reset=按Y键重新启动计算机应用注册表键值,按任意键退出稍后自行重启:
if %reset%==y (goto :reboot) else (goto :noreboot)
set /p reset=按Y键重新启动计算机应用注册表键值,按任意键退出稍后自行重启:
if %reset%==y (goto :reboot) else (goto :noreboot)
:reboot
shutdown /r /t 0
shutdown /r /t 0
:noreboot
echo 感谢您的使用!
choice /t 2 /d y /n>nul
echo 感谢您的使用!
choice /t 2 /d y /n>nul
exit
:no
cls
echo off
echo 系统中已存在×××1.test.com、×××2.test.com和×××3.test.com连接,按任意键退出 & pause
cls
echo off
echo 系统中已存在×××1.test.com、×××2.test.com和×××3.test.com连接,按任意键退出 & pause
转载于:https://blog.51cto.com/tingdongwang/685729