windows下使用cmd命令远程重启tomcat服务

时间:2022-12-19 12:53:23


新建一个bat文件,将下面的代码复制到bat并执行即可。

备注:需要修改登录账号、密码、IP
echo login on
@echo off
echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs


echo WScript.Sleep 1000 >>telnet_tmp.vbs


echo sh.SendKeys "y">>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs


echo WScript.Sleep 1000 >>telnet_tmp.vbs


echo sh.SendKeys "账号">>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs


echo WScript.Sleep 1000 >>telnet_tmp.vbs


echo sh.SendKeys "密码">>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs


echo WScript.Sleep 5000 >>telnet_tmp.vbs


echo sh.SendKeys "net stop Tomcat_8028">>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs


echo WScript.Sleep 20000 >>telnet_tmp.vbs


echo sh.SendKeys "net start Tomcat_8028">>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs


start telnet IP地址


cscript //nologo telnet_tmp.vbs
echo login success


pause



net命令的使用: net start/stop service service可以从服务管理里面查看得到,在运行里面输入services.msc,右键任一服务的属性,即可查看该服务的服务名称及显示名称:
windows下使用cmd命令远程重启tomcat服务