Batch files are quick and easy to create and use, and having the ability to do so is still quite useful for just about anyone of any background or skill level, even for a programmer!
With the exception of “ControlVAC” (written in August 2016) and possibly some other upcoming content we may add in the future, most of these files were written over the years and only kept around for reference. While they were all useful at one point in time, mostly these days many won’t be (at least for the specific purpose they were created.)
Regardless, the techniques found here are good examples of how to create and work with batch files, and with this knowledge you can create something truly valuable for you!
Note: All batch is presented in plain text format and is not executable until renamed to remove the ‘.txt‘ file extension. Any requirements and instructions for usage will be in the header of the file itself.
Compatibility: Most everything is written and tested on Windows XP, Windows 7, or Windows 8. While most of my batch is written with NT based compatibility in mind, with the exception of the occasional text parsing from command output that Microsoft might have changed, (and none of that batch is included here to date,) all batch should work on Windows 2000 – Windows 8 without issue, but we cannot guarantee full compatibility on every version of Windows!
Tiny/simple demonstration of ‘For…’ loops on files in a directory, this batch was written for later versions of the original d7 technician tool to be used in WinPE environments, which required some .dll and .ocx files to be registered (via regsvr32) in a WinPE environment before use.
Originally I wrote this in a pinch for a web server with out of control log files, this will archive files older than xx days across multiple folders by using rar.exe (optionally you can replace this with your favorite archive utility without fear of a botched command line parameter, because the date logic is done entirely within the batch, not the archive program!!!) Very organized code with short but meaningful comments, good to learn with!
(August 2016!) ControlVAC was created to control instances of the Audio Repeaters (MME) for Virtual Audio Cable on my personal system, and to distribute to my co-workers and others to make it easier to use. Virtual Audio Cable does exactly what it sounds like it should do, allowing you to route audio input/output to/from different apps using virtual devices recognized by Windows as real input/output devices. The setup and usage is quite advanced however, but fortunately the Audio Repeaters allow for arguments to be passed to the executable responsible for controlling the I/O behavior of your ‘virtual cables’ and that in itself makes this batch file possible.
This batch was designed to route audio between an external microphone/speakers and two different headsets, all connected to the same PC (allowing simultaneous usage or routing of specific audio streams to different input/outputs) as well as the separating and/or mixing of audio streams from various sources that can be used with calling apps/video conferencing, broadcasting, and recording software. Specifically this batch file can enable/disable routing of the Windows audio subsystem separately between these various devices and our ‘meeting’ (and/or broadcasting) application used on the Foolish Tech Show, in addition to the ‘green screen’ software’s audio recording interface (or another audio/video recording application which would need all audio mixed together from all sources, especially since that audio cannot be mixed in output to the broadcasting software due to horrible echo/bad audio effects!) With this setup, we can do things like have two people on a shared audio/video stream from the same PC, take live calls during our broadcast, route sound effects or any Windows audio to the broadcast without echo or harsh sound issues, etc. etc.
While not terribly complex or interesting (as far as batch syntax) it can be awfully useful if you are interested in or use Virtual Audio Cable.
Delete Zero-byte files in any given directory with optional recursion for subdirectories and report logging. I admit it is easy enough to sort by size in explorer or your favorite file manager, and delete all files of a certain size, but normally this is part of an automated batch routine and just saves me TIME. Recently I had to use this as a stand-alone batch on a system with 21,000 phony zero-byte .DLL files in both the Windows and System directories. Well, the 21,000 I used DelZBF on took a good 15 minutes. At first I thought, how inefficient! Next I tested the manual way, getting the sort view in explorer and trying to select them, forget waiting on the delete operation to start, after the same 15 minutes I gave up and ran DelZBF on that directory too.
A MUST SEE. Please see the file itself for a full explanation. FindQ’s (short for Find Question Marks) seeks out malware hiding behind phony names, which may show up in a console window as having a “?” in the name, where in explorer all you will see is the expected letter. Ex: You may note a folder which appears to be “Symantec” but is actually “S?mantec” and contains a malicious executable inside. This is possible as the command console (cmd.exe) doesn’t interpret unicode characters as Windows Explorer (explorer.exe) does, replacing unrecognized characters in the file system with a question mark.
This example batch shows you how to execute code depending on which OS (Windows XP-7, and 32 or 64bit) you are running on.
Slightly better than “net start servicename” this quick batch will stop services prior, wait xx time, start and wait xx time before moving on to the next service, retest to see if they failed xx number of times, retry xx number of times to start them if failed. I recently had to write a quick batch to start some services in a particular order and wait a certain amount of time before starting subsequent services. In my allotted time for the job I just decided to make the script a little more flexible. Easy configuration inside the batch itself, separate from the main code.
See where your batch is going wrong; generate a detailed log! This batch file will accept your batch file via parameter including Drag and Drop, and generate a detailed report on your batch helping you to troubleshoot any problems you may have. Provides at-a-glance information about the file itself and it’s execution environment, in addition to it’s actual execution. Read notes in the header!
Very simple batch to demonstrate FOR loop usage, but it originally had another purpose. Love apps from www.nirsoft.net? Me too. For a time, they were not available as one packaged download. I configured a weekly schedule task to run batch files using the Linux->Windows port of WGET.EXE and InfoZip’s UNZIP.EXE to download all the apps (wget checked for newer versions only) and unzip them into one directory, renaming all the readme.txt files to a %zipfilename%_readme.txt format. This is the portion of that batch that does the unzip/rename operations, with the wget/download part excluded. Why only this part? Because currently the apps are available as one packaged download (See Nir Sofer’s blog for NirLauncher) however it does not include all of his apps and readme’s. I modified this for someone in a forum who needed the functionality as they would download the missing or newer version apps to add to the main NirLauncher package. Hopefully Nir Sofer will release all apps with auto-update functionality soon.
Join us for live tech chat, product questions, support, and technical training right here!
Customer or not, you are welcome to drop in and discuss anything ‘tech’ with us!
ATTN: Podnutz fans and those who know Eric Arduini If you’ve benefited from Podnutz in the past or you...