i need a script for windows 11 (bat file) that i can run that automatically restarts…
- User
i need a script for windows 11 (bat file) that i can run that automatically restarts tailscale
Assistant
Here's a simple batch file script to restart Tailscale on Windows 11:
@echo off echo Restarting Tailscale... echo. echo Stopping Tailscale service... net stop Tailscale if %errorlevel% neq 0 ( echo Failed to stop Tailscale service. pause exit /b 1 ) echo Waiting 2 seconds... timeout /t 2 /nobreak >nul echo Starting Tailscale service... net start Tailscale if %errorlevel% neq 0 ( echo Failed to start Tailscale service. pause exit /b 1 ) echo. echo Tailscale has been successfully restarted! pauseTo use this script:
- Open Notepad and paste the code above
- Save it with a
.batextension (e.g.,restart-tailscale.bat) - Right-click the file and select "Run as administrator" (required for service management)
Alternative version using SC commands:
@echo off echo Restarting Tailscale... echo. echo Stopping Tailscale service... sc stop Tailscale echo Waiting 3 seconds... timeout /t 3 /nobreak >nul echo Starting Tailscale service... sc start Tailscale echo. echo Tailscale restart complete! pauseThe first version provides better error checking, while the second is more concise. Both require administrator privileges to work properly since they're managing Windows services.
- User
now make that script make itself run automatically whenever its 19:40 or 7:40 pm local time of the computer itw as run in
Assistant
Here's a batch script that restarts Tailscale and sets up automatic execution at 7:40 PM daily:
@echo off setlocal enabledelayedexpansion :: Get the full path of this script set "SCRIPT_PATH=%~f0" set "TASK_NAME=TailscaleAutoRestart" :: Check if running with /restart parameter (called by Task Scheduler) if "%1"=="/restart" goto :restart_tailscale :: First-time setup: Create scheduled task echo Setting up automatic Tailscale restart at 7:40 PM daily... echo. :: Check if task already exists schtasks /query /tn "%TASK_NAME%" >nul 2>&1 if %errorlevel% equ 0 ( echo Task already exists. Updating... schtasks /delete /tn "%TASK_NAME%" /f >nul 2>&1 ) :: Create the scheduled task schtasks /create /tn "%TASK_NAME%" /tr "\"%SCRIPT_PATH%\" /restart" /sc daily /st 19:40 /ru "SYSTEM" /rl highest /f if %errorlevel% equ 0 ( echo. echo ✓ Scheduled task created successfully! echo ✓ Tailscale will automatically restart daily at 7:40 PM echo. echo Running initial Tailscale restart now... echo. ) else ( echo ✗ Failed to create scheduled task. Make sure you're running as administrator. pause exit /b 1 ) :restart_tailscale echo Restarting Tailscale... echo Timestamp: %date% %time% echo. echo Stopping Tailscale service... net stop Tailscale if %errorlevel% neq 0 ( echo Failed to stop Tailscale service. if "%1" neq "/restart" pause exit /b 1 ) echo Waiting 3 seconds... timeout /t 3 /nobreak >nul echo Starting Tailscale service... net start Tailscale if %errorlevel% neq 0 ( echo Failed to start Tailscale service. if "%1" neq "/restart" pause exit /b 1 ) echo. echo ✓ Tailscale has been successfully restarted! echo Timestamp: %date% %time% :: Only pause if not running from Task Scheduler if "%1" neq "/restart" ( echo. echo The script will now run automatically every day at 7:40 PM. pause ) exit /b 0To use this script:
- Save it as
tailscale-auto-restart.bat - Right-click and "Run as administrator" (required for both service management and task creation)
- The script will:
- Set up a daily scheduled task for 7:40 PM
- Perform an immediate restart of Tailscale
- Show you confirmation that the automation is set up
What it does:
- First run: Creates a Windows scheduled task and restarts Tailscale immediately
- Subsequent runs: Automatically triggered daily at 7:40 PM to restart Tailscale
- Logging: Shows timestamps when restarts occur
- Error handling: Provides feedback if something goes wrong
To remove the automation later:
schtasks /delete /tn "TailscaleAutoRestart" /fThe script runs as SYSTEM with highest privileges to ensure it works reliably even when no user is logged in.
- Save it as
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.