新建一个.vbs文件
将这个文件放在:(win8及以上)“C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup” 或(win7及以下)“C:\Documents and Settings\用户名\「开始」菜单\程序\启动” 路径下
内容为:
set ws=WScript.CreateObject("WScript.Shell")
ws.Run "C:\Users\###\Desktop\sss\bag\emqx-5.3.2-windows-amd64\bin\startTest.bat",0
其中路径替换为安装电脑中"startTest.bat"文件所在路径。
startTest.bat 文件内容为:
@echo off
setlocal
set mqttPort=18083 ::监听mqtt端口号
echo Testing connectivity to localhost:%mqttPort%...
start /d "C:\Users\linyang\Desktop\sss\bag\emqx-5.3.2-windows-amd64\bin" mqttStart.bat ::mqttStart.bat文件路径(mqtt程序所在路径的bin文件夹下)
timeout /t 5 /nobreak >nul
:: 使用 PowerShell 检查端口可达性
powershell -Command "$ErrorActionPreference = 'Stop'; $result = Test-NetConnection -ComputerName localhost -Port %mqttPort%; if ($result.TcpTestSucceeded) { exit 1 } else { exit 0 }"
if %errorlevel% equ 0 (
echo Port %mqttPort% is not reachable,run again.
start /d "C:\Users\###\Desktop\sss\bag\emqx-5.3.2-windows-amd64\bin" mqttStart.bat ::mqttStart.bat文件路径(mqtt程序所在路径的bin文件夹下)
echo reStart...
timeout /t 10 /nobreak >nul
echo call mqtt.bat
start /d "C:\Users\###\Desktop\sss\bag\emqx-5.3.2-windows-amd64\bin" startTest.bat ::startTest.bat文件路径
) else (
echo start tomcat
start /d "D:\workPackage\apache-tomcat-8.5.33-windows-x64\apache-tomcat-8.5.33\bin" startup.bat ::tomcat的启动文件路径
start /d "C:\Users\###\Desktop\sss\bag\RunTest" RunTest.exe ::RunTest.exe文件路径
)
endlocal
@echo on
mqttStart.bat文件内容为:
emqx start