Share |

Marcus' Macro Blog

Mostly tips, tutorials, articles and news about Macro Scheduler & Windows Automation
May 2nd, 2006 by Marcus Tettmar

When running command line tools, applications or batch files it is often necessary to watch the resultant command window. E.g. to detect their completion you can have the script wait until the command window has closed. The trouble with this is that when you run batch files the title of the command window is always just “C:\WINDOWS\system32\cmd.exe”. So if your script starts more than one batch file, or you have other CMD windows open, how do you know which CMD window is which?

Well how about predefining the window title of the new CMD window? We can do this with the Windows start command. The start command starts a new CMD window and lets you give it any title you want and run a program/command at the same time. For more info type start /? at the command prompt. So we can use this in Macro Scheduler with the Run Program command:

Run Program>cmd /c start "Window Title" "c:\bla\something.bat"

This enables us to monitor this specific window to see when the batch file completes:

Run Program>cmd /c start "My Window One" "c:\stuff\reports.bat"
WaitWindowOpen>My Window One*
WaitWindowClosed>My Window Two*
MessageModal>Finished!

Now you might be wondering why we’d want to do the above when you can just make the script wait for the program or command run to finish by setting RP_WAIT to 1, like this:

Let>RP_WAIT=1
Run Program>c:\stuff\reports.bat

Well, you may need to manipulate the window at some point during the process. Or you might want the script to detect if the batch file is taking too long to complete, like this:

Run>cmd /c start "My Window" "d:\test.bat"
WaitWindowOpen>My Window*
Let>WW_TIMEOUT=120
WaitWindowClosed>My Window*
If>WW_RESULT=FALSE
  //Timed out, email Administrator
  SMTPSendMail>admin@domain.com,..........
Endif

Using the start command like this to set the CMD window’s title makes it much easier to distinguish between other command windows and ensure we manipulate the one belonging to our batch file.

Related posts:

  1. Sending Keys to Invisible or Unfocused Windows

2 Responses to “Changing CMD’s Window Title”

  1. Csaba Gabor says:

    Um, at least on XP, you know that you can change the title of a Cmd window with…
    title My favorite title

    Csaba Gabor from Vienna

  2. pawan says:

    Amazing & great… thanks a lot!!!!!!!!! i have scratched my a** to get something like this.

Leave a Reply