[Sharing] Simple .bat files for starting/restarting/stopping Serv

Yo…

Just sharing this since someone might have use for it.
It’s simple and non-harmful. The code works from the bat files current directory so place the them right
under your Blynk server folder, let the server be on the same level as the batfiles and make sure you
only have the version you intend on running in that folder.

Also note I use javaW as opposed to java. This makes it windowless, feel free to edit or use as you wish.

Copy paste this into notepad and save it as the titles.

1 Start.bat

echo off
setlocal enabledelayedexpansion

set title=Blynk Server
set rootFolder=%cd%
set dataFolder=%rootFolder%\Data
set serverConfig=%rootFolder%\server.properties
cls

for %%X in ("%rootFolder%*.jar") do (
set serverVer=%%~nxX
Start “%title%” /MIN javaw -jar “%%~nxX” -dataFolder “%dataFolder%” -serverConfig “%serverConfig%”
)

echo.
echo.
echo.
echo Starting Blynk server with the following parameters…
echo.
echo Server: %serverVer%
echo Title: %title%
echo Root Folder: %rootFolder%
echo Data Folder: %dataFolder%
echo Server Config: %serverConfig%
echo.
echo.
echo Window will close in 10 seconds
timeout /t 10 /nobreak>nul[/details]

[details=2 Restart.bat]echo off
setlocal enabledelayedexpansion

set title=Blynk Server
set rootFolder=%cd%
set dataFolder=%rootFolder%\Data
set serverConfig=%rootFolder%\server.properties
cls

echo.
echo.
echo.
echo Ending server in 3 seconds
timeout /t 3 /nobreak>nul
taskkill /F /IM “javaw.exe”>nul
echo.
echo Server ended. Restarting in 3 seconds…
timeout /t 3 /nobreak>nul
call “.\1 Start.bat”

[details=3 Stop.bat]echo off
taskkill /F /IM “javaw.exe”
[/details]

Edit for typo

1 Like

It would be even more nice if you can just send along a parameter for stopping and starting :wink:

I guess it would ^.^ feel free to edit

IF "%~1"=="" GOTO error
IF "%~1"=="start" GOTO startserver
IF "%~1"=="restart" GOTO restartserver
IF "%~1"=="stop" GOTO stopserver

:startserver
REM start stuff goes here

:restartserver
REM restart stuff here

:stopserver
REM and stop stuff here

:error
REM Error message here "echo please user start/restart/stop parameter"

This should basically do the trick :slight_smile: But with your stuff in it. It’ll only require one file. I made something similar for Linux, but bash scripting is easier and way more flexible than batch files. I also made an automatic update script which checks for new files on the github page. It could probably be done with powershell too (which I would recommend over using batch files any day).

1 Like

Hey I’d like to ask you, would’nt this require the use of a command prompt to pass on those commands or 3 other batfiles that call this one ^^? Working my way away from the cmd prompt was the goal, just have it clickable.

No and yes. You can set parameters in the link you make. So you could make three links (start, stop, restart) or indeed use a command prompt. I think you can have the file ask for input too, but it was too long ago since I did that.

You may want to invest a little time to get this working in PowerShell. You can than have a nice popup asking you what you want to do.