How to Send a Message to a Remote User Session (MSG) in Batch Script
Before forcefully rebooting a server for Windows Updates or logging off a user who has left their session open, professional administrators always send a warning. The old net send command was retired years ago, replaced by the modern, robust msg command. This tool allows IT staff to pop up a message box on another user's screen instantly, regardless of what application they are running.
This guide explains how to use msg to communicate critical alerts to remote sessions.
Why Send Messages via Command Line?
- Maintenance Alerts: Warning all logged-in users that the "File Server will restart in 5 minutes. Save your work."
- Idle User Notification: Asking a user on Session ID 2 if they are still working before terminating their connection.
- Emergency Broadcast: Alerting the entire office to a critical issue (e.g., "Email is down, please use Slack") without relying on email itself.
The msg command is the direct replacement for net send. It works on all modern Windows versions (Pro and Enterprise editions only) and does not require the "Messenger" service to be running.
Method 1: Sending to a Specific User
To message a specific person (e.g., jdoe), you simply target their username.
@echo off
setlocal
:: Check for admin rights
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges are required to message other users.
pause
exit /b 1
)
:: Verify msg.exe is available
where msg >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] msg.exe is not available on this Windows edition.
echo [NOTE] The msg command requires Windows Pro, Enterprise, or Server.
pause
exit /b 1
)
set /p "USER=Enter username to message: "
if "%USER%"=="" (
echo [ERROR] No username entered.
pause
exit /b 1
)
set /p "TEXT=Enter message: "
if "%TEXT%"=="" (
echo [ERROR] No message entered.
pause
exit /b 1
)
echo [PROCESS] Sending alert to "%USER%"...
:: /time:30 keeps the message on screen for 30 seconds
msg "%USER%" /time:30 "%TEXT%"
if %errorlevel% equ 0 (
echo [SUCCESS] Message delivered.
) else (
echo [ERROR] User may not be logged in or is unreachable.
)
pause
Method 2: Broadcasting to All Users (The '*' Wildcard)
If you need to alert everyone currently logged into the system (including console and RDP sessions), use the asterisk *.
@echo off
setlocal
:: Check for admin rights
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges are required.
pause
exit /b 1
)
set /p "MSG_TEXT=Enter broadcast message: "
if "%MSG_TEXT%"=="" (
echo [ERROR] No message entered.
pause
exit /b 1
)
echo [PROCESS] Broadcasting system-wide alert...
:: * targets all sessions on the local server
msg * /time:60 "%MSG_TEXT%"
if %errorlevel% equ 0 (
echo [SUCCESS] Message broadcast to all active sessions.
) else (
echo [ERROR] Broadcast failed. msg.exe may not be available.
)
pause
Creating a Scheduled Reboot Warner
This professional script warns users at decreasing intervals before initiating a reboot, giving them ample time to save.
@echo off
setlocal
echo ============================================================
echo Reboot Countdown Notifier
echo ============================================================
:: Verify admin rights
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges are required.
pause
exit /b 1
)
:: Verify msg.exe is available
where msg >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] msg.exe not available. Cannot send warnings.
pause
exit /b 1
)
echo.
echo [WARNING] This script will send three warnings and then
echo REBOOT the computer automatically.
echo.
set /p "CONFIRM=Proceed with reboot countdown? (Y/N): "
if /i not "%CONFIRM%"=="Y" (
echo [INFO] Cancelled.
pause
exit /b 0
)
:: 1. First Warning (10 minutes out)
echo [1/3] Sending 10-minute warning...
msg * /time:60 "NOTICE: Server %COMPUTERNAME% will reboot in 10 minutes for scheduled maintenance. Please save all work."
timeout /t 300 /nobreak >nul
:: 2. Second Warning (5 minutes out)
echo [2/3] Sending 5-minute warning...
msg * /time:60 "WARNING: Server %COMPUTERNAME% will reboot in 5 minutes! Save your work NOW."
timeout /t 240 /nobreak >nul
:: 3. Final Warning (1 minute out)
echo [3/3] Sending final warning...
msg * /time:55 "CRITICAL: Server %COMPUTERNAME% is rebooting in 60 seconds! Save immediately!"
timeout /t 60 /nobreak >nul
:: 4. Reboot
echo [PROCESS] Initiating reboot...
shutdown /r /t 0 /f /c "Scheduled Maintenance Reboot"
echo ============================================================
Common Pitfalls and How to Avoid Them
"Msg is not recognized"
The msg.exe utility is not present in "Windows Home" editions. It is only available in Pro, Enterprise, and Server editions.
"Error 5: Access Denied"
To send a message to another user's session, you must run your Batch script (and CMD) as an Administrator. Standard users can only message themselves.
Advise your users that msg does not support rich text or images. It is a plain-text tool designed for short, urgent operational messages.
Best Practices for Administrative Messaging
- Keep It Brief: The message box is small. Keep your alerts under 250 characters to ensure they are readable.
- Use /server: You can send a message to a remote computer by adding
/server:PC-NAME. This requires the remote PC to allow RPC connections. - Target Session ID: If two users named "Administrator" are logged in, use
qwinstato find the Session ID (e.g., 2) and send specifically to it:msg 2 "Log off now".
The msg command has a /w (Wait) switch. If used, your script will pause until the user clicks "OK" on the message box. This is useful for mandatory confirmations.
Conclusion
Sending messages to remote user sessions via Batch script is a critical capability for any system administrator managing a multi-user environment. By replacing the obsolete net send with the modern msg command, you can ensure that your maintenance warnings and emergency alerts are seen instantly by the people who need to see them. This professional approach to user communication reduces help desk calls, prevents data loss during reboots, and keeps your operations running smoothly across the entire Windows network.