Rob van der Woude's Scripting Pages

Third Party Batch Files

I often get scripts for review, and several scripters without a scripting site of their own have asked me to publish their scripts on my site.

On the other hand, I get many many questions for support on the scripts I publish on my site.

I often need to read and reread my own scripts several times before I can recall the choices made and the code used when asked for support several years later.
I cannot guarantee I'll be able to fully understand and support code written by others, which could become a potential source for disappointments.

But it would be a shame not to publish these scripts.

Hence this page and the following disclaimer.

Disclaimer: The following scripts are all created by visitors of my site, not by me.
They are Third Party Scripts, "Not Invented Here".
Questions about these scripts will be forwarded to the authors/creators.




by Jiri Hofreiter

Note from the author:

I created simple batch to randomly shuffle lines from input.

usage: type list.txt | shuffle.bat

Best regards,

Jiri Hofreiter

  Download Shuffle.bat

Back to the top of this page... ]



by Denis St-Pierre

Note from the author:

I don't believe you have a script to determine what version of Windows you are running in CMD batch files.
So here you go:

Denis St-Pierre

BTW: Nobody seems to have the Version numbers that show up when you type VER in CMD for each version of Windows/DOS, not even wikipedia has this.
It sounds silly but it does come in handy at times.

I agree, a list with VER outputs for all Windows versions would be quite useful.
As would including the ServicePack information in VER's output - right now you get identical output for Windows XP "base" and XP SP3!

Notes: 1 To make Denis' code work in Windows 2000 you need to either install FINDSTR or use FIND (without the /L switch) instead.
  2 If WMIC is available (Windows XP Professional and later) you can find the Windows and servicepack versions:

WMIC OS Get Caption,CSDVersion,Version

  Download WinVer.bat

Back to the top of this page... ]



by Justin

Note from the author:

I wrote this script for something to use for work and thought other people might be interested in it, it generates a calender for an input year.
I have added a reasonable amount of comments to the script to make it easy to understand.

As one of the comments states it's an xp batch file but looks like it should work for win 2000 and above but is untested.....

The output for 2011 looks like this:

Calendar.bat screenshot

Notes: 1 For box drawing characters it is essential to choose the proper codepage.
In this batch file, that is done by the lines:
FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
CHCP 850 >NUL 2>&1

The first line saves the current codepage in a variable %CodePage%, the second sets the codepage to 850.
Before exiting the batch file, the original codepage is restored:
CHCP %CodePage% >NUL 2>&1
  2 Special thanks for Wikipedia, I couldn't have written the HTML and PHP code to correctly display the source code without their Box drawing characters page.

  Download Calendar.bat

Back to the top of this page... ]


List Mounted Removable Drives

by Carlitos

Whenever I need to know what removable devices are available, I use the following command:

ECHO List Volume | DISKPART | FIND /I "Removeable"
Note: Some Windows versions use the word "Removable", others use "Removeable" (note the extra "e" in the latter).
To circumvent problems, replace FIND /I "Removeable" with FINDSTR /R /I /C:"Remove?able"

The DISKPART command will show a list like this:

Volume 7     J                       Removeable      0 B
Volume 8     K                       Removeable      0 B
Volume 9     L                       Removeable      0 B
Volume 10    M                       Removeable      0 B

However, as Carlitos pointed out, this command requires administrative privileges.
Carlitos needed "ordinary users" to list their removable drives and came up with the following solution:

  Download Removables.bat

Back to the top of this page... ]


Progress Meter

by Roy Holt

Note from the author:

This script takes a variable passed to it containing the current progress in percent (0 to 100) and it displays a progress bar followed by a numerical percentage in the title bar, then returns control back to the calling script or routine.
This meter stays visible and is unaffected by scrolling text in the Command Prompt window and adds a negligible delay to the continued execution of the main script.
It can be called as often or seldom as desired during the execution of the main script and can be passed the current status in any regular or irregular increment.
This has been tested in Windows XP, 2000 and 2003.
Note that depending on the active title bar font selected, a lower case "L" (l) may appear better than the uppercase "i" (I) used in the script.

For an example, save it to your current directory (as ProgressMeter.bat) and call it from a Command Prompt window like this:

ProgressMeter.bat 62

It should display a progress meter in the title bar which is 62% filled, followed by the text "62%":

Progress Meter in action

This batch file is intended to be used as a subroutine in other batch files to give these a more professional look.
When you do use it, please include the complete header with credits plus the source URL:

  Download ProgressMeter.bat

Back to the top of this page... ]



Get all domain user details.

by Florian Dörr

Note from the author:

I just started to build a script to gather userdetails from all users in a domain based on your script disabled.bat.

But i guess i found a small "issue" when a user has a blank in his username.


It does work, but i don't know how the "net user /domain" output would look like if a username is longer than 25 characters.


To start gathering the details to all users in the domain, execute GetAllUserDetails.bat.
This script calls GetUserDetails.bat which actually does the extraction.
You can also use GetUserDetails.bat as standalone. To do this just pass the username you want to check as a parameter.
e.g. GetUserDetails.bat robvanderwoude

I don't know about the long account names either, as I don't have access to NT 4 systems anymore.
But if I recall correctly, I think there used to be a 16 character limit on NT 4 account names.

Note: These scripts will fail on non-English Windows versions.

For Active Directory based domains, the recommended way to list user account details would be the use of the DS Tools DSQUERY and DSGET.
These tools are language independent, and spaces or "special" characters in account names or properties are no problem.

  Download GetAllUserDetails.bat and GetUserDetails.bat

Back to the top of this page... ]



Convert decimal numbers to hexadecimal.

by Richard K. Bussey

Note from the author:

I recently needed to display return codes (errorlevels) in hexidecimal format. So I wrote a little script to do it. I could have done it quicker with javascript, but wanted to use strict cmd sripting. So here it is.

Richard K. Bussey

  Download DecToHex3P.bat

Back to the top of this page... ]


DHCP Scopes

Obtains all active DHCP Scopes authorized in the domain

by Josh Murray

Note from the author:

Script will automatically enumerate and scan all authorized DHCP servers on the domain, creating a log of all active scopes.
Windows Server 2003 only.
Useful for finding the current list of user subnets in a large Active Directory network, for deploying to/scanning etc.
Keep in mind, if there is a network outage when run some sites won't show up, but all errors will be logged.

Sample Error.log:

Server not responding: 
Server unreachable 
Server unreachable
Server unreachable
Server unreachable
Server unreachable
Server unreachable
DHCP Service may be disabled:  
Unable to determine the DHCP Server version for the Server
Unable to determine the DHCP Server version for the Server

Sample Scopes.txt:     -    -Active       -Name            -Description      -  -Active       -e.g. Corp Users -Non IT users          -  -Active       -                -            -  -Active       -                -        -  -Active       -                -           

Dhcp.txt has the unparsed log, which I personally leave in case I need more info than this, but could delete it as well, as the real purpose is to just display all active scopes, which is very useful when you have hundreds of servers.

Josh Murray

I didn't test this script myself.
The usual warnings apply, as always: "use at your own risk" and "test, test, test and test".

  Download DHCPScopes.bat

Back to the top of this page... ]



"insane" behaviour of IPCONFIG?

by Brian Williams

Note from the author:

I was scripting in Windows 2003 and discovered a method for obtaining a CR with no LF. It only works in XP and 2003 WITH delayed expansion turned on, but I was running a FOR loop with 'IPCONFIG' as the command I was parsing. My results ended up getting displayed all weird with one of the results at the left of my screen overwriting some of my echo'd statements. I started trying to capture the output that IPCONFIG was displaying and came up with this:

Brian Williams

Now this is what I call creative scripting.
You have to see it to believe it.
Too bad it only works in Windows XP and Server 2003.

Use the download link to download the code, as some browsers may remove the trailing spaces, that are absolutely required in this case.
Problems were also reported with wrong carets in copied and pasted code, so again, please use the download link to download the code.

  Download Twirly.bat

Back to the top of this page... ]


Configure Windows Firewall

by Willi Huber

  Download AddMySQLPort.bat

Back to the top of this page... ]



by Jos van der Esch

Always assigns the drive letter U: to a USB-stick.

Notes from the author:

Connect always drive U: to the USBpen

Connect always (a second) driveletter U: to a USBpen.
Windows automatically assigns a free drive letter to a USB device.
If you want for some reasson that the user always works on the same driveletter U: you can put the files: "AutoRun.inf", "Make-U.bat" and "Make-U.ico" in the root of the USBpen. For a different diveletter you can mainipulate the driveletter as given in the batchfile "Make-U.bat". You can also use "AutoRun.inf" to start an application form or on the USBpen.
Put the USBpen in the computer:
in the "POPup" [Connect USBpen to U:] klick [OK]
OS: Windows XP + SP2 (SP1 don't start autorun on a USB device)

If you are happy with this tool let me know:

  Download USB-driveletter.bat

Back to the top of this page... ]



by Jos van der Esch

Notes from the author:

Windows automatically assigns a drive letter to a USB device, without checking network mappings to see if a drive letter is really available. One solution to this problem is to start using drive letters high in the alphabet, but many environments use F: as the first mapped network drive.

Problem: USB devices are not available because they are mapped to the same drive as a network mapping. You cannot expect users to disconnect drives. In a locked-down environment, you might simply want to disable the use of USB storage devices. You can use XP's disk management to assign a different drive letter to the device, which will be remembered. Instead of changing the mapped drive letter of your USB hdd, you can change for example the drive letter that is used by your CD-Player.

Supported OS: Windows XP (Prof)

MVol-E remounts automatically any physical volume from the letter E: to the first available letter R:, T:, V: or X:.

If you are happy with this tool let me know:

  Download MVol-E.bat

Back to the top of this page... ]



by Bruno Mota

Notes from the author:

The program should return to the proper date even if it is left running past midnigth, but if the date changes some miliseconds before it finishes you might end up a day short.

About the groundhog, there is this movie with Bill Murray where he is a reporter covering the 'Groundhog Day'. But for some reason time does not pass, and every time he wakes up in the morning it is still GH Day. Much like my routine (as far as the program it is calling is concerned).

  Download Groundhog.bat

Back to the top of this page... ]



by Jeff Montgomery

Catalog your CD-ROMs.

Notes from the author:

Have a lot of burned CDs?
Don't remember what's on them all?
Want an easy way to find those files?"

You can change the first two from "%4" to any value you want (up to 8). (Make sure you modify the first so that it LOOKS for
In this way, you can have up to 99999999 files listed. (Lots of discs!) I use 4 for convenience, but not annoyance.

Change "w:\" to your CD-/DVD-ROM drive

What does it do?
It calls itself until it reaches the specified number of digits.
(You can change it so it uses HEX if you want, just add " A B C D E F" after the 9 in the first line.
Once it gets there, it checks to see if the file %1%2%3%4.txt exists already.
If it doesn't, it uses that file, snaps a recursive, show-all-files directory of the CD-ROM (W:\), pauses for a keystroke, and exits...
    -- recursive, so it keeps going, advancing to 0001.txt, 0002.txt, 0003.txt, ....
When you're done, hit ^C, and tell it "yes"
You'll have a text file for every cd you had in.
(The smart thing to do is number the CD to match the output.)

Then, when you're looking for "that rotten install file I can never find.exe", search the text files for "that rotten install file I can never find", and you'll have a list of all the CDs your file's name was on... (Or for MP3 discs containing Michael Jackson songs, search for "Jackson") etc. etc.

And it's all one small, compact, miniscule batch file.

You can modify it as needed for your own use, but I take pride in having done something this simple.

And the really nice thing is that if you decide to destroy a CD, just remove its text file, and the next CD you catalog will get that number... and then advance to the next missing number.

One caveat: Once you have a large number, it might take a long time to go. (I've 230 CDs, and it's 4 seconds on a PIII 400... so once you're in the thousands, we're talking maybe a minute to get to the first empty spot.)
Other than that, it'll do wonders. It creates the listing in the current directory — you can specify a directory in the "if exist" and "dir/s/a" lines if you want them in a specific directory on the system.

And obviously, you'll need to switch CDs between pauses... or they'll be the same!

The :ok and :error tags are old, but ideal places for making changes and testing them...

But here it is:

  Download CD-Cat.bat

Back to the top of this page... ]



by Jacopo Lazzari

Find the first available drive letter.

Notes from the author:

I made a small batch to list all unused drive letters (to easily select on which letter to mount a Ram/Virtual Disk).
Following is the batch file, maybe it can be useful to you or some other visitor of your site.

  Download FreeDriveLetter.bat

Back to the top of this page... ]



by Gordon Schumacher

Move pictures to a unique directory to prevent overwriting existing pictures.

Notes from the author:

I recently bought my daughter a cheap digital camera. It presents itself to the computer as a hard drive. However, it does not have a function to where it stores the date on-board. It names the pictures IMGxxxxx.jpg, so if you try to just copy them over, you'll overwrite the previous set of pictures.

So, I figured I'd write a quick batch file to do the transfer for her that would manage the file renames. I guess that means that she won't be learning the details of using Windows Explorer just yet, but that's probably mean less hunting for where she copied the pictures this time!

It's mostly made out of bits and pieces of scripts I found on your site, but I figured I'd send it along anyway. It might save someone some time!

  Notes from me:
Notes from me: 1 This batch file assumes that the date is always preceded by the day of the week.
Some Windows versions, I think Canadian XP is one of them, do not use this day-of-week date notation, in which case this batch file will fail.
See my DATE and TIME in NT pages for alternatives.
  2 You may need to modify D:\DCIM\ to match your own camera's path.
You might even consider integrating Carlito's Removables.bat to automatically detect the proper drive...

  Download MovePictures.bat

Back to the top of this page... ]



by Shannon Zielinski

Check your network traffic.

Notes from the author:

Here is the code to my netstat live alternative. [...] It isn't 100% accurate, but I have compared it to analogx netstat live and tried to make the results as similar as possible.

  Notes from me:
Notes from me: 1 This batch file will run continuously, and CPU usage on your computer may soar to 100%.
  2 You may have to adjust the IP address used in the PING command.
See my batch delays page for details.

  Download NetStatLive.bat

Back to the top of this page... ]


page last uploaded: 2016-09-19, 14:56