Is it possible to create a popup reminder message with batch scrip, that will repeat the popup message every one hour? This is a part of a long batch script and i cant use any other utility or script. It has to be batch script.
Asked
Active
Viewed 3,822 times
0
-
Batch can't do pop-ups. Use vbscript instead. It's technically not third party, since it comes installed with Windows. – SomethingDark May 12 '15 at 13:32
-
1check this - http://stackoverflow.com/a/25925201/388389 – npocmaka May 12 '15 at 13:36
-
I cant use vb script as because this is a part of long batch script. – Ari Dey May 12 '15 at 13:50
-
1npocmaka's suggestion for the win.`mshta "javascript:alert('hi!');close()"` – rojo May 12 '15 at 14:22
-
This script for one time. but how do i repeat that? – Ari Dey May 12 '15 at 14:43
1 Answers
0
If all what is needed is a popup message every hour, include the following line in the batch file
start "" /b cmd /q /e /c">nul 2>&1 (for /l %%a in (0) do (msg console this is the message & ping -n 3601 localhost ))"
This will spawn a background cmd
instance that will use msg
to show the popup and ping
to wait, all inside an infinite loop.
edited to adapt to comments
As I said, maybe the best way to handle it is to leave to the scheduler the message sending, and control the task from a script or command line
This is a copy/paste/change of an existing code i had at hand that wraps argument passing to schtasks
. The basic idea is
a) Create a task to send the message
popup.cmd create taskName "this is the message to send each hour"
b) The popup task can be enabled / disabled when needed
popup.cmd disable taskName
popup.cmd enable taskName
c) When not needed, the task can be removed
popup.cmd remove taskName
@echo off
setlocal enableextensions disabledelayedexpansion
rem Where the tasks will be created
set "tasksFolder=PopUpTasks"
rem Get the task name from arguments
call :getTaskName "%~2" taskName
rem Check list of arguments
set "command="
for %%a in (
create list remove enable disable status run
) do if not defined command if /i "%%~a"=="%~1" (
set "command=%%a"
rem List and creation commands have different arguments
if "%%~a"=="create" (
call :create "%tasksFolder%\%taskName%" "%~3"
) else if "%%~a"=="list" (
call :list "%tasksFolder%"
) else (
rem The rest of the commands require a valid task name
rem so we first test and if everything is OK, continue
call :checkTaskExist "%tasksFolder%\%taskName%" && (
call :%%~a "%tasksFolder%\%taskName%"
) || (
call :noTask "%tasksFolder%\%taskName%"
)
)
)
rem If something failed or if we did not found a valid command, show usage
if errorlevel 1 call :showUsage
if not defined command call :showUsage
goto :eof
:create taskName message
if "%~2"=="" exit /b 1
schtasks /create /f /tn "%~1" /sc HOURLY /mo 1 /np /tr "msg.exe console \"%~2\""
goto :eof
:remove taskName
schtasks /delete /f /tn "%~1"
goto :eof
:enable taskName
schtasks /change /enable /tn "%~1"
goto :eof
:disable taskName
schtasks /change /disable /tn "%~1"
goto :eof
:status taskName
schtasks /query /tn "%~1"
goto :eof
:run taskName
schtasks /run /tn "%~1"
goto :eof
:list tasksFolder
schtasks /query /v /fo list /tn "%~1\\"
goto :eof
:getTaskName taskName returnVar
setlocal enableextensions disabledelayedexpansion
set "taskName=%~1"
if "%~1"=="" for /f "tokens=1-2 delims=:" %%a in ("%__cd__:\=.%") do set "taskName=%%a.%%b.%~n0"
endlocal & set "%~2=%taskName%"
goto :eof
:checkTaskExist taskName
>nul 2>nul schtasks /query /tn "%~1"
exit /b %errorlevel%
:noTask
echo(
echo(ERROR: The requested task ["%~1"] does not exist
exit /b 1
:showUsage
(
echo(
echo( Usage:
echo(
echo( %~n0 COMMAND ["taskName"] ["message"]
echo(
echo( With COMMAND :
echo( CREATE "taskName" "message"
echo( REMOVE "taskName"
echo( ENABLE "taskName"
echo( DISABLE "taskName"
echo( STATUS "taskName"
echo( RUN "taskName"
echo( LIST
echo(
) & exit /b %errorlevel%

MC ND
- 69,615
- 8
- 84
- 126
-
-
@AriDey, the code is indended for batch file usage. From command line, replace `%%a` with `%a` – MC ND May 12 '15 at 15:41
-
It worked but the problem it is not working when i close the cmd window and in case of my script it is not possible to keep the cmd window open. So is it possible to close the cmd window and still run the script? – Ari Dey May 12 '15 at 16:09
-
@AriDey, sorry, the code is intended to be used inside a running batch file. Under the new indicated scenario, I think it is easier to create a scheduled task to execute the `msg` command each hour and use scripts or commands to enable/disable the task as needed. – MC ND May 12 '15 at 16:22
-
even i need this code for a batch file....... but only problem is that when i run the code it keeps cmd window open. is it possible to to run the code with out keeping cmd open? – Ari Dey May 13 '15 at 05:47
-
@AriDey, answer updated. Probably most of the code is not necessary, but i had it at hand. – MC ND May 13 '15 at 10:12