• Home
  • About 404TS
  • Contact

404 Tech Support

Where IT Help is Found

  • Articles
    • Code
    • Entertainment
    • Going Green
    • Hardware, Gadgets, and Products
    • Management
    • Network
    • News
    • Operating Systems
    • Security and Privacy
    • Software
    • System Administration
    • Talking Points
    • Tech Solutions
    • Web
    • Webmaster
  • Reviews
  • Media
    • Infographics
    • Videos
  • Tech Events
  • Tools
    • How do I find my IP address?
    • Browser and plugin tests
  • Get a Technical Consultation
You are here: Home / Articles / Code / Advanced Batch Scripting

Advanced Batch Scripting

2008-10-21 by Jason

I’d like to share four utilities that can improve your batch (DOS) scripting by making them more user-friendly, more versatile, and more dynamic. With these tools, you’ll gain a variety of abilities that allows you to do more with batch scripting and make your utilities more polished/enjoyable to the end users.

The four utilities are: Sleep, BATtoEXE, CHP (Create Hidden Process), and CMDOW.

We’ll start off with the most obvious, sleep. Sleep, like the function of the same name in other programming languages, simply tells your machine to idle for a set amount of time.

sleep 10

Tells your script to idle for ten (10) seconds and then resume.

sleep -m 5000

Tells your script to idle for 5000 milliseconds and then resume (equivalent to 5 seconds).

You can get sleep.exe from Microsoft in the Windows Server 2003 Resource Kit.

BATtoEXE also gives a lot of its mystery away in its title. This little tool, unlike the other three listed here, is the only one that you run on your script instead of running from inside your script. BATtoEXE converts your batch script into an executable. This will prevent people from viewing or changing the code and helps establish a ‘final version’ of your script.

BATtoEXE interface
BATtoEXE interface

You can choose to have a Console application or a Ghost application. A console application will show the output of your script where a ghost application will invisibly do all its operations in a completely black command prompt window. Don’t use a ghost application if you rely on user input or the window will hang at that point. So, edit your script for any Pause or other input commands before making a ghost application.

You can also use the Include line to bundle a single attachment with your script. You can bundle, mentioned above, sleep.exe and then where ever your new executable script is run, it will have sleep.exe with it.

After compiling your code you’ll have a .exe file so that individuals won’t view or edit the source. It’s also more portable.

The version numbers and other info shows up in the exe
The version numbers and other info shows up in the exe

Download BATtoEXE here.

CHP is a simple tool to make your batch scripts more stealthy. Let’s say you need to spawn some processes off during your script to gather information, change permissions, or something like that. If you put CHP in front of the process it will execute almost completely invisibly to the end-user. The only thing that they could see (if they were looking) would be the process in the task manager.

Run another batch script silently:

CHP cmd.exe /c "d:my batch file.bat"

Launch a process like notepad or calculator silently:

CHP calc.exe

Launch notepad and have it print a file:

CHP notepad /p "C:receipt.txt"

This hidden property of the process is also something to be careful of. You want to be sure to close the process or else it will stay open, silently running in the background. Download CHP and see more examples from here.

The final utility is the most powerful and interesting: CMDOW.

You can use CMDOW to interact with windows. You can minimize, maximize, tile, hide, close, and make many other manipulations of the scripting window and other windows open, identifying them by their Handle ID.

You can do a lot of things to affect all windows or the window running the script easily.

To tile all windows vertically:

CMDOW /TV

To minimize all windows:

CMDOW /MA

To maximize the window running the cmdow command:

CMDOW @ /MAX

To mimize the windows running the cmdow command:

CMDOW @ /MIN

Now, if you want to control a different window besides the one running the script, you’ll need to find the handle ID of the currently open process. To do this run:

CMDOW

If you want to narrow it down to just those windows listed in the task bar, run:

CMDOW /T

Lists the windows open in my task bar.
Lists the windows open in my task bar.

Let’s say I wanted to change the caption of PrimalTask. Look at the row above in the screenshot and we’ll use the handle 0x0503B4.

Another way to get the handle of any windows named PrimalTask would be to use the command:

cmdow PrimalTask

That will pull up only windows named PrimalTask. Put double-quotes around the caption if it contains a space between words.

To rename our PrimalTask window, we’ll use CMDOW again and the handle we found out earlier:

cmdow /REN “To Do List”

Before and After shot of CMDOW Renaming
Before and After shot of CMDOW Renaming

You might use CMDOW to minimize your script while it’s running and rename the window to display the status of the script as it goes along. CMDOW can be used for a lot of other things as well to help polish off scripts. Read more about it and download it from here.

Filed Under: Code, Software, System Administration, Tech Solutions

Trending

  • Configure Flash as click-to-play in Chrome while whitelisting your favorite, trusted sites
    In Tech Solutions
  • PHP Basics with WordPress and phpBB
    In Software, Tech Solutions, Webmaster
  • Infographic: Your Personal Data Online
    In Infographics, Security and Privacy

Latest Media Posts

Find Out Where To Download SNES ROMs

Find Out Where To Download SNES ROMs

Multifunctional Video Conversion Tools – Wondershare Video Converter

Multifunctional Video Conversion Tools – Wondershare Video Converter

  • Popular
  • Latest
  • Today Week Month All
  • Access to the resource [servershare] has been disallowed Access to the resource [servershare] has been disallowed
  • What is the AllJoyn Router Service on Windows 10? What is the AllJoyn Router Service on Windows 10?
  • Read the Event Logs on Windows Server Core Read the Event Logs on Windows Server Core
  • How a DirecTV bill really works in 2015 How a DirecTV bill really works in 2015
  • SOLVED: “This modification is not allowed because the selection is locked.” SOLVED: "This modification is not allowed because the selection is locked."
  • How Virtual Reality Supports Mental Health Therapy How Virtual Reality Supports Mental Health Therapy
  • Key Strategies of Successful Coin Listing on Exchange Key Strategies of Successful Coin Listing on Exchange
  • Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting
  • Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams
  • customer contactless payment for drink with mobile phon at cafe counter bar,seller coffee shop accept payment by mobile.new normal lifestyle concept The Latest Innovations In Payment Technology
Ajax spinner

Elevator Pitch

404 Tech Support documents solutions to IT problems, shares worthwhile software and websites, and reviews hardware, consumer electronics, and technology-related books.

Subscribe to 404TS articles by email.

Recent Posts

  • How Virtual Reality Supports Mental Health Therapy
  • Key Strategies of Successful Coin Listing on Exchange
  • Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting

Search

FTC Disclaimer

404TechSupport is an Amazon.com affiliate; when you click on an Amazon link from 404TS, the site gets a cut of the proceeds from whatever you buy. This site also uses Skimlinks for smart monetization of other affiliate links.
Use of this site requires displaying and viewing ads as they are presented.

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in