Wednesday, April 16, 2025

Using batch scripting to shut down, restart, and log off the computer

1. Open Notepad or Notepad++.

2. Copy and Paste Batch Script

@echo off
:start
cls
echo Select an action:
echo 1. Shut Down
echo 2. Restart
echo 3. Log Off (Local Only)
set /p action=Enter your choice (1-3):

set /p computer=Enter Computer Name:

if "%action%"=="1" (
    shutdown /s /m \\%computer% /t 0
) else if "%action%"=="2" (
    shutdown /r /m \\%computer% /t 0
) else if "%action%"=="3" (
    echo Log Off can only be done on the local computer.
    shutdown /l
) else (
    echo Invalid selection.
)

pause
goto start 

3. Save the file as "remote-shutdown.bat" without quotes.

4. Save the file to the desktop, where you can locate it easily.

5. Double left-click the program to run it.

 

You have it!