I am making batch scripts for various purposes, and want to make it so that after a command is completed, a message dialog is displayed that will declare the results.

For instance, if I make a script delete a specific object, I would like it to display a user-defined dialog. I would prefer to use this format for the window title and text values:

x=msgbox("%MESSAGE%" ,0, "%TITLE%") 

How can I add this (above) to my script to be displayed after the task (below) is complete?

rmdir "%TARGETPATH% 
3

1 Answer

You can use command redirection with && or & to execute a proceeding command after the first command completes. You can set it to execute the proceeding command after the first command was successful, or directly after the first command executes regardless of the first command result.

The trick is to have the batch script put the VB msgBox function and applicable values it uses into a temp script that will later be executed via wscript.

This should all work out of the box without installing any third party tools so it's Windows native.


Batch Script

Note: You will need to use the syntax of SET x=msgbox "%TITLE%",0,"%MESSAGE%" rather than what you have for this to work but that's a minor adjustment only.

@ECHO ON :Routine1 SET TARGETPATH=C:\Path\Folder SET COMMAND=rmdir "%TARGETPATH% SET TITLE=This is my message title SET MESSAGE=This is my message body SET tmpmsgbox=%temp%\~tmpmsgbox.vbs SET x=msgbox "%MESSAGE%",0,"%TITLE%" ECHO %x%>"%tmpmsgbox%" %COMMAND% && WSCRIPT "%tmpmsgbox%" EXIT 

Redirection

 commandA & commandB Run commandA and then run commandB commandA && commandB Run commandA, if it succeeds then run commandB 

Further Resources

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy