@echo off setlocal EnableDelayedExpansion set cur_dir=%~dp0 set service_name=rpyc schtasks /query /tn "%service_name%" 1>NUL 2>&1 if not ERRORLEVEL 1 ( GOTO EXIST ) else ( GOTO NOTEXIST ) :EXIST REM If the service has been existent, just delete it schtasks /delete /f /tn "%service_name%" :NOTEXIST REM Create a schedule task, run once at the startup REM please make sure the service file is located in the same directory of this script. REM REM Here you can replace the /tr with "start.bat" schtasks /create /ru "SYSTEM" /sc once /tn "%service_name%" /tr "python %cur_dir%\rpyc_classic.py --host 0.0.0.0"