VBScript MD5Hash and IsHex Functions to Calculate MD5 File Hashes

Recently I was tasked with synchronizing directories between two different servers. Because files can change, become corrupted or otherwise altered without changing any of their attributes, it was pretty essential to ensure that these files were exactly the same.

There are a few utilities out there that can do this for you but one of the best suited is the security algorithm MD5. Well, obviously, VBScript does not have a built in MD5 summing function. There are some .NET libraries that do this pretty easily but unfortunately their methods are not exposed to VBScript (someone correct me if I’m wrong).

So to facilitate this MD5 summing I tried a couple of different methods. The first one, a pure VBScript solution, was functional. The first couple of files I tried it on seemed to go off without a hitch. That was, until I tried a 1.9MB file. That file took 59 minutes to run through the pure VBScript solution. Obviously this is totally impractical considering the size of some files.

The next method I tried was a compiled command line implementation of MD5. You’ll need to download this and make sure the “exe” is in the same directory as your VBS. This works great and is the method that I settled on. Hashing is quick, very quick. The same 1.9MB file happens well under a second. Several hundred meg files in just a second or two. Well within a reasonable margin. So here is the script and a quick example of usage:

Another side note, I wrote a “IsHash” function that returns true or false based on whether the string you pass is a valid hex value (since all MD5 hashes are returned as a hex string).


Leave a Comment