![]() |
Windows Scripting Samples
|
Links to sections on this page:
|
|
Number File In order to get my photos to sort right for slide shows, I add numbers (and a dash) to the beginning of the file names. That's a hassle to do manually, so this script was created. Just drop your files one-at-a-time on this script and it will stick progressively higher numbers on the beginning of the file names. The numbers go up 10 at a time to allow you to make a few last-minute changes without having to renumber the whole collection.
Date Name
Do you have a process that kicks out an identically-named file every
day? If you want to rename them so they don't overwrite each other,
naming
them with date seems the most natural solution. You pass it a file name
like this:
start /w DateName.vbs
C:\PROGRA~1\FNORDW~1\LOGS\REFERE~1.TXT
or a quoted long name like this:
start /w DateName.vbs "C:\Program Files\Fnord Web
Server\logs\Reference
Log.txt"
And it would rename the corresponding
"C:\Program Files\Fnord Web Server\logs\Reference
Log.txt"
to
"C:\Program Files\Fnord Web
Server\logs\1999-12-28-Reference
Log.txt"
I used year-month-date to make sorting easier.
Time Date Name Same as the above DateName, but this one adds time as well. Prefaces the file name with year-month-date-hour-minute-second
DirList Written by Fred Coleman. Fred actually got this one written up in the German PC Magazine! This willl create an "index.htm" file for any given directory. Two weeks after I decided nobody would ever need to index a directory, I found myself needing to do it dozens of times. So I got Fred's code posted so YOU won't have to build your solution from scratch!
Index Similar in concept to Fred's script above, except I wanted mine to display icons. Amazingly, I found a way to do it. Brute force and obscure graphics formats to the rescue! For a real-life sample, most of the links on this page take you to (very simple) index pages made by this script.
Sync Dirs If you have two different folder "trees" you need to synchronize (or update), this might help. In my case, I had a "tree" that was a single folder full of utility programs. I had another tree that had those same utilities arranged in folders sorted by category. Trouble is, when I update them, I always put the updates in the flat single-folder tree. The category tree never got updated. That's where this script comes in! It looks at every file in every folder in the destination tree (my utilities organized by category), then searches for the matching file in the source tree (my single folder of unsorted files). If it finds a match, it checks file modification dates. If a newer version is available in the source tree, it copies it to the destination tree. Note that the source and destination trees do NOT have to have the same structure. An effect of unstructured tolerance is that only existing files in the destination are processed. If the source tree has extra files in it, they won't be copied over to the destination tree because the script has no idea where they would go in the destination tree!
Folder
File Properties
Uses the Shell.Application/Namespace/GetDetailsOf function to retrieve
all the file details you'd normally get by right-clicking a file. In
addition to the normal file attributes exposed by the
Scripting.FileSystemObject, using Shell.Application also gets you data
like the file version, description, manufacturer, owner, title, audio
format, and sender name. Obviously not all properties apply to all
files. This script generates a CSV report showing all the details for
every file in a folder. Just drop a folder on the script. Or
just
steal this code as a reference when you need to do something like show
all files owned by "Administrator".
Spaces
To Tabs
I used to write all my scripts with spaces for indenting because it
looked better under Notepad. Unfortunately, it also made it harder to
edit under Notepad! So I changed all my scripts to use tabs instead of
spaces. And I used this script to do it. Put it in the starting folder
and run it. It will verify what file extensions you want to modify, and
convert all instances of four spaces to a single tab character. Simple,
actually.
Hosts
Sort If
you're the sort of person who uses (or misuses) the HOSTS file, you may
have been frustrated by how difficult it is to update, sort, and
organize a large HOSTS file. This is a set of scripts that make it
possible to do those
things with almost no effort. The scripts aren't fast, but I'm rarely
in a hurry.
Functions
This will search all your source code and document the functions and
subroutines it finds. As written, it searches VBS and ASP files, but
this is easily modified via a constant. It searches for
lines beginning with "Function " or "Sub ", and again, this is easily
modified via a constant. The script starts running in the directory
where it is located and produces a tab-delimited report named after the
script file (like "Functions.txt").
Trim Log Files
I have lots of log files that do nothing but grow. So I wrote this to
trim
them down to a reasonable size. I run it as a scheduled task every
night.
The log files must have entries on separate lines. This script keeps
the
most recent entries at the end of the log and throws away old entries
at
the beginning of the log. Pass it a file name and a desired max size
(between
a hundred bytes and a million bytes). Use it like this:
start /w TrimLogFiles.vbs "c:\logs\server.log" 32767
Delete Old Files Let it loose on the network "share" drive every once in a while. It deletes files in and below any directory you select based on age. Designated file extensions can be protected from deletion.
No Old Files
Similar to the above script based on common requests from system
administrators. It can take both arguments from the environment, the
command line, or interactively from the user. It deletes designated
file extensions. By popular request, the script now deletes empty
subdirectories. However,
because this is a top-down, list-driven script, it only deletes the
lowest-level
empty directory in each branch of the directory tree on each run. If
you
run it on a regular schedule, it will eventually get around to deleting
all empty unused subdirectories. Use it like this:
start /w NoOldFiles.vbs "S:\Share" 90
No
Old Folders
This one only deletes old folders (as defined by the folder's "last
modified" date). Of course, if it deletes an old folder, it will delete
all other files and subfolders under it regardless of the age of those
files or subfolders! This script only takes arguments from the command
line. Give it a starting folder (which will not be deleted!) and the
maximum age of a folder (in days) you wish to keep. This script is
recursive, not list-driven... which doesn't actually matter in this
particular case.
No Small Files
If it's little, who is going to notice it's missing? Or even better, if
it's little, it must have been a bad download, so it it should be
deleted.
No Brackets
If you've ever dragged files out of your IE temporary internet files
folder (the easiest way to investigate linked style sheets and scripts
or get copies of multimedia files you've played), maybe you've noticed
how everything gets renamed with bracketed numbers! A perfectly
reasonable "styles.css" gets changed to "styles[1].css". No problem if
it's only a couple of files, but a pain if you're grabbing
hundreds of files! This script will rename all the files in a
single directory to return the names to normal.
Recursive Lower Case Starts at a directory you specify and changes all file names in and below that directory to lower case. I needed this when I moved a web site onto a case-sensitive Unix web server.
Recursive No Spaces
Starts at a directory you specify and removes the spaces from all file
names in and below that directory. I needed this when I moved a web
site
onto a Unix web server.
CRLF to CR
Converts DOS/Windows text (with CRLF line terminators) to Apple-type CR
line terminators. Mostly useful as a pre-processor for other conversion
programs which interpret both CR and LF as newline characters. I use it
before I convert text into Palm PDB/DOC format.
LF to CRLF
Converts UNIX text (with LF line terminators) to DOS/Windows CRLF
terminators. Great to fix text that got munged up during download from
a *nix server to a Windows machine.
Search And Replace
Searches through any single plain-text file and replaces text you
specify.
Use it like this:
start /w SearchAndReplace.vbs "C:\MyFile.txt" "old
text" "new
text"
If you don't want to use a script to do your searching and replacing,
try these: HisGrepShip
GNU
Utilities Simtel
Text Utilities Sbs2.com
Global Search And Replace Starts at a directory you specify and edits all files (you specify the target file extensions) in and below that directory to replace text. I use it to fix web pages, scripts, and batch files when servers, files, or directory names get changed! As written, it crashes if it finds a file with no extension. An easy fix, but like I said, I wrote this to solve my problem. And I use extensions. So there.
Code Block Search And Replace Just like the above Global Search script, but this one lets you replace entire multi-line blocks of code. I needed this when I needed to replace a common piece of JavaScript scattered throughout all my web pages with an improved piece of code.
Update This is for those of us who have grown a bit too big to hand-update each web page, but are too cheap or too particular to surrender to using a real site editor. The "big boys" use special comment tags to identify html code sections, so that's what this script does. If you can invest the time to put tags in your page (like put <!--LOGO_START--> and <!--LOGO_END--> around your html logo graphic code), this script will run through all your web pages and update all the code between the targeted tags.
Sub Copy Copies a single file into multiple subdirectories. I have several "user" subdirectories, and I need to distribute files to all of them. I put this script in the parent directory of the users' directories, then drop the file I want copied onto the script. I could have used the NT FOR command to do it, but scripting lets me extend the code to handle user interaction and logging.
Change File Name Case
Changes all files in a single directory you select to upper or lower
case.
I needed to change case when I needed a way to "mark" files. You know,
kind of like a file attribute? I have files that are "guesses" and
files
that are "verified" and I didn't want to create a database to keep
track
of which category each file was in. My Win32 box doesn't care about
file
name case, but code can tell if a file has an upper or lower case file
name! It's just like having another file attribute! Keep it in mind...
Zero
Files
Sets all files in and under a given subdirectory to zero bytes. Why?
Because sometimes you want files to exist (but not take up any room)
just to stop automated copy or download operations from retrieving new
copies.
Zero
Mirror
Creates a mirror of an existing subdirectory somewhere else -- except
all the copies of the files are zero bytes. This would allow you to
recreate an entire CD's file system layout on a floppy disk. Maybe that
floppy would satisfy an upgrade program's requirement to see the
original disk? Or use the script to make a
copy of a file system in a way that would allow the Windows file search
function to be used. Like create an index of all your (non-music) CDs.
Sanitize
Helps to prevent recovery of files you've previously deleted. This
script runs through all your fixed hard drives and fills all the empty
space with spaces. Once it runs out of room on the hard drive, it
deletes all the files it created. To move as fast as possible, it
starts out by creating 32MB files until it runs out of room. Then it
cuts back to 16MB, 8MB, and so on, all the way down to 512 bytes to
make sure all empty space is filled. The use of file copying instead of
file creation and a one second delay when switching file sizes seems to
handle the disk caching problem pretty well. Not meant to protect you
against the NSA, just against someone in your IT department with a
recovery utility or sector editor.
Debug
Written to give the same output as the DOS "DEBUG" program. I used this
to look into how scripting reads binary files as text streams. By
keeping
the same format, I was able to make easy side-by-side comparisons.
Answer
-- Scripting does just fine until it hits a short run of binary zeroes.
Then it's lost. Now that I know, this script really has no use!
Except... Maybe in a locked-down computer, the DEBUG program is
prohibited. If so, you can use this script to see what type of
line-termination characters are used in a a file you're having trouble
with or if that file contains real spaces or those pesky non-breaking
spaces.
Size
Solves a common batch file problem: How to compare file sizes. From a
batch
file, use it like this:
if errorlevel 2
goto ERROR
It will return an errorlevel of zero if the statement is true, an
errorlevel
of one if it is false, and an errorlevel of two if there is an error.
Operators
>, <, =, >=, and <= are all valid and must
be
quoted. File
names only need to be quoted if they have embedded spaces or other
delimiters.
The size value never needs to be quoted (but it can be if you want to).
Depending on your OS, you may get better results using "cscript"
or nothing
in place of "start /w".
Date
Another common batch problem. How to compare file dates. Just like the
above "size.vbs" except this one compares file modification dates. A
newer
file is "larger" than an older file. From batch, use it like this:
start /w date.vbs
"C:\SomeFile.txt" ">"
"C:\OtherFile.txt"
if errorlevel 2
goto ERROR
The above example is asserting that the "SomeFile.txt" is newer than
the "OtherFile.txt". It will return an errorlevel of zero if the
statement
is true, an errorlevel of one if it is false, and an errorlevel of two
if there is an error. Operators >, <, =, >=, and
<= are all
valid
and must be quoted. File names only need to be
quoted if they
have
embedded spaces or other delimiters. Depending on your OS, you may get
better results using "cscript"
or nothing in place of "start
/w".
|
|
|
|
Wait
For Title
Windows
Scripting has an "AppActivate" function that will give focus to a
window based on the
window's title. It returns True or False based on whether the window
existed and focus could be shifted there. This script uses
that
technique to wait for any program. The downloadable zip file includes a
"test.bat"
to demonstrate the script.
Wait
For Exe
WMI (Windows Management Instrumentation, standard on Windows 2000, XP,
and newer, and a free
download for Win9x)
allows scripts to check the actual executable name of all running
processes. So if you know the name of the program, this makes it easy
to wait until all instances of that program are finished. The
downloadable zip file includes a "test.bat" to demonstrate the script.
Kill
Title
This script uses the Scripting "AppActivate" function to activate
applications based on their title bar text, then uses the "SendKeys"
method to send an application-killing "Alt-F4" keystroke.
Kill
Exe
Again using WMI, this allows you to terminate all instances of running
processes based on the executable name.
Schedule
This scheduling script is useful in situations where you have several
programs you need to launch, but you don't want to go through the
password-changing hassle of using the task manager to launch them all.
Set up the Windows Task Manager to launch this script when the computer
has been idle for a few minutes. That makes it a poor-mans "service"
since it will run even if you log out. And you only have to update your
password one time in the task manager. And, and, and... It's only a
SCRIPT, which means even in most locked-down environments, this
scheduler won't have to go through an approval or exception process.
WSC
You
probably don't think of a WSC as a way to run other programs, but
that's exactly what I do with them. You can write scripts that run
programs you don't have on your computer. You can use the code in a WSC
without registering it on your computer. And you can use a WSC file
without giving it a WSC file extension. A bunch of little-known items I
decided to mix in with my SFX
script to
do some interesting things. Well, interesting to me!
Pop-Up Window Killer An extension of the above KillTitle. I tried a popular browser popup killer, and while it worked fine, I thought I could do the same thing with scripting. So I did. Sure, it doesn't have all the features, but it works, it's free, and you can modify it easily to suit your purposes. It works by maintaining a list of "bad" window titles. If focus can be shifted to one of those bad titles, then an Alt-F4 key (or Ctrl-F4 for AOL people) is sent to close the bad window. Most popups start out with an "about:blank" window title, so that gives you a great head start.
Invisible
Shows how to use the Shell "Run" method to run any program, script, or
batch file invisibly. You'll want to be sure whatever you run invisibly
won't require user input, because, well, you can't click a button you
can't see!
PEMenu
This
script is designed to be used with the BartPE PE-Builder.
PE-Builder
allows you to make a bootable CDROM that can run Windows programs.
There is no better way to recover from a virus or from a corrupted hard
drive than from a bootable CDROM. You can add your own programs to the
CDROM, but most programs require a separate "plugin" to be built so
they don't run directly from the CDROM. That's a lot of work...
However, if you have a collection of simple utilities capable of
running directly from a CDROM, this script will build all the necessary
"plugin" files for you. This one script generates one plugin that will
support hundreds of your utility programs. That's a lot less work!
|
|
|
|
Progress Bar Use Internet Explorer to create a graphical progress bar you can control from your script.
Browse
for
File
Automatically use the "Shell.Application" where you can, and use
Internet
Explorer where you can't. Either way, you can offer the user a simple
graphical
way to select a file. BAD NEWS:
The "Shell.Application" file browsing trick used an undocumented value
(8192 or 16384) to get a reference to a file. This doesn't seem to work
reliably under XP.
Choose One Use Internet Explorer to present the user with a pull-down list of choices.
Text Entry
Use Internet Explorer to allow the user to enter multiple lines of
text.
|
|
Articles
This script was written to allow me to download and convert online
stories,
news and opinion articles. The idea is that after I use this script to
get the text all in one place, I convert it and put it on my Palm so I
can read it during slow times. This script just delivers plain text, so
it can be used to feed Palms or PocketPCs or text readers. Great for
people like
me that are too cheap to pay for AvantGo. Comes complete with sample
batch
files that will download USA Today, PC Magazine, the San Jose Mercury
News,
Security Focus, Scientific American, Science News, Discovery, Asimov's,
Analog, Fantasy & Science Fiction, the Infinity Plus web site,
and
more! I add another site every time I run out of reading material. BONUS:
I include a sample script that merges this "articles" script with the
below "makedoc" script to do the complete download, conversion to Palm
format, and launch of the Palm installer.
MakeDoc
My favorite command-line Palm text conversion utility, makedoc.exe,
is
almost impossible to find on the web. Worse, some companies lock
their
computers down and won't let users install any extra programs and
utilities.
This simple script should fly under the radar of any lock-down policy
and
allow you to convert plain text into the standard Palm "doc" pdb
format.
The only shortcoming is that it doesn't do compression.
Unwrap If you visit the newsgroups (like alt.binaries.e-book), you'll find several raw book scans. They look just like book pages. Absolutely not ready for conversion into anything. This script unwraps the text, removes the page headers and numbers, cleans up hyphens, corrects some common scanning errors, and generally goes a long way towards making the text usable - all with no user interaction. The script ignores any file that appears to already be unwrapped. If the script is run with cscript, it displays it's status. A DOS comand like "cscript.exe unwrap.vbs MyEbook.txt" would clean up the ebook "MyEbook.txt". If you want, you can also drag etext files and drop them on the script.
UnGutenberg
Creates a Palm PDB file from a Gutenberg
etext file. All the classic stories you were supposed to have read in
high
school and college are available via Gutenberg. All the classic poems
and
fairy tales you want to read to your kids are also there. Thanks to the
Palm, you can take them with you and not have to read them on a monitor
or print them out (both really bad options). This script unwraps the
Gutenberg
etext, "sanitizes" the etext by removing all the Gutenberg "small
print",
and tries to set the Palm document name to match the actual book title.
Accepts both raw text and zipped files as input. Needs PKUNZIP
and MAKEDOC in the path.
|
|
Speech
Overview
Microsoft offers two ways of programming text-to-speech applications:
SAPI 4 and SAPI 5. I believe SAPI 4 can be installed on everything from
Windows 95 on up. Windows 2000 has SAPI 4 pre-installed (but it is
virtually always broken) and XP has SAPI 5 installed. Both typically
only have
one voice. Install
or re-install SAPI 4 from here
(it's only 825KB). Even though you install SAPI4 correctly, Microsoft
will fail to "register" all the DLLs correctly. You will need to run a
command like this to fix things:
Alternatively, you can double click each DLL in the Windows / Speech
folder and select the "Regsvr32.exe" file when asked what program
should be used to open DLL files. You can find several very
good
SAPI 4 voices at the Microsoft
Agent user download page. I like the American
English and
British English voices. Very good stuff. If you download the SAPI
SDK 4 Suite
(40MB), and open it with WinZip, you'll find two files
"mstts.exe" and "msttsv.exe" inside which will install about twenty
special effects SAPI 4 voices. Robots, echoes, whispers, that sort of
thing. Kids love them. Of course, you can install the entire "Suite" if
you want. But unless you're a programmer, you don't want to install the
entire SDK suite! As far as SAPI 5, the only two ways I know of (from
Microsoft)
are:
1 -- Install the entire Speech
SDK 5.1
(68MB). That gets you SAPI 5 and three voices... and a bunch of samples
that can't be removed. No, the voice quality is no better on SAPI 5
than on SAPI 4. The one big difference is that SAPI 5 allows you to
easily convert text directly to an audio file without having to play it
and record it.
2 -- Install Microsoft
Reader, then install the Microsoft
TTS component. The TTS installation does
require Reader to
be there. I haven't found a way around that. But having Reader is a lot
less overhead than having an entire SDK! Unfortunately, the "Reader"
route only gives you a single voice.
Speech
Test
This HTA file will give you a report your computer's voice
capabilities. It will provide links to allow you to fix any problems it
finds. Which means you don't have to understand how to
register
the speech DLL files (the green text above). You can just point and
click your way through the repair.
Speak
This script will read any plain-text file out loud. It really, really
tries to convince you to run it with CSCRIPT so you can see the text
displayed as it's being read. You must have SAPI 4 or 5 installed. If
you don't have voice capabilities, the script will prompt you to
download
SAPI 4. This sript is rather crude. Both the SAPI SDK downloads have
equivalent utilities that do the same thing.
Story
Reader
This is an HTA file that extends the above "Speak". Extends it quite
well, thank you! By using an HTA,
StoryReader can speak and display text without having to worry about
which engine (cscript or wscript) it is running under. StoryReader also
does smart unwrapping and sentence
identification, allowing you to use
almost any format of plain text for a story source. StoryReader accepts
command line arguments allowing you to specify which file to read, a
starting point in the
file, and what voice to use to read the story. Because nobody likes
command lines, I've also included an HTA called
"VoiceChooser.hta" that
lets you easily select which voice will read your stories. But wait --
there's more! StoryReader and VoiceChooser both contain the voice
repair capabilities found in the above "SpeechTest". Also, I've
included another file called
"Menu.hta" that
will automatically create clickable links for both of the other hta
files and for all your stories!
Voice
Test
This is the "Hello World" of text-to-speech. It checks seven
different text-to-speech objects (six SAPI 4 and one SAPI 5), and
checks every voice available to each object. It tells you which objects
succeed or fail, and it will identify and speak in every voice possible.
Text
To Wave
This script will save any plain-text file as a WAV file. You must have
SAPI 5 installed. If you don't, the script will suggest you download
the SAPI 5 SDK. Create your own "books
on tape" (or on CDROM). SAPI5 allows you to save to virtually any
format of WAV file. I've built constants for the most common choices
into the script.
|
|
Array To Bmp Creates a 16-color BMP (Windows Bitmap) file from an array. BMP files can be displayed as inline graphics by Internet Explorer, Mozilla, and by virtually all graphics programs.
Array To Xbm Creates a black and white XBM (Sun Bitmap) from an array. XBM files are plain text and can be displayed by Netscape and Internet Explorer. Traditionally, XBM is used to display small icons. The XBM files this script produces require 6 bytes per pixel. The disadvantage of the large file size is balanced by the universal browser support. IE will only display XBM files locally if they are associated with mime type "image/x-xbitmap". Very few Windows graphics programs can be used to work with XBM files ("IrfanView" at www.irfanview.com is the easiest, but also try "The Gimp" at www.gimp.org and the command-line "ImageMagick" utilities from www.imagemagick.org).
Array To Pbm Creates a PBM (portable bitmap) in version 1 format (black and white, plain text) from an array. The PBM files produced by this script require about 2 bytes per pixel. PBM files can be displayed in Mozilla and by most decent graphics programs.
Web and Thumbnail Creator Takes a folder full of your JPG digital camera photographs and creates web-sized (or email-sized) JPEG photos and smaller GIF thumbnails for all your photos. The script uses the EXIF data present in your camera photos to automatically rotate your new web and thumbnail pictures the correct way. Your original pictures are never modified. I wrote this script to automate the conversion of photos for web-based slide shows. The script needs (and you'll need to get) the free "GflAx" ActiveX object from XNView. If you want more customization than this fully automated script delivers, you might want to check out the following two scripts...
|
|
2Phone If you have a movie or a folder full of movies you'd like converted so they'll play on your phone, this should help. It even works on Media Center "dvr-ms" recordings! Most phones will play MP4 files, so that's what this script produces. Subtitles and movie descriptions are embedded directly in the movie file for convenience (where they can be enabled and disabled by your player), but SMI and SRT subtitle files are preserved in case your movie player needs them. Drop a movie file or a folder full of files on the script and let it work! All the hard work is done by the "ffmpeg", "MP4Box", "atomicparseley", and "ExtractClosedCaptions" programs, the locations of which are documented both in the script.and the "ReadMe" file.
Slide
Show
If you have a collection of sound files with matching pictures (in
other words, pictures with recorded narration), this script will
create the HTM web pages needed to display your files in a
framed JavaScript
self-advancing slide show. The narration in
your sound files will play
while the matching picture is on-screen. Just run the script and answer
a few questions. Every question has a default answer already given, and
in most cases you'll be able to simply accept the default. The script
was written to work best on Windows with Internet Explorer, but it
degrades gracefully (losing the auto-advance feature) on other browsers
and operating systems.
Text
Slide Show
If you have a collection of pictures and (optionally) related
plain-text files, this script will create all the HTM web pages needed
to display your files in a framed JavaScript
slide show. You
don't need to know how to
create a web page! The script will match up your pictures and text
files by name and create all the web pages for you.
Virtual
Dub
Creates a jobs file for the free video editor VirtualDub. With
this script,
you can save your settings and have those same settings applied to
every video file in a directory. I wrote this because I had lots of
video captures I needed to process.
Make ASX Run this script and point it to a bunch of movie or sound files and it will create an ASX file which will allow you to use MediaPlayer to play them sequentially.
Make SMIL Run this script and point it to a bunch of movie files and it will create a SMIL file which will allow you to use QuickTime or RealPlayer to play them sequentially.Jpg
2 Asx Run
this script to create an ASX slide show from a directory full
of
JPG, GIF, PNG, or BMP pictures.
Repeat
ASX
If you'd like to set up an infinite loop of media files (either a
single sound or video file or an ASX collection) you can drop your
existing media file on this script. A new ASX file will be
created which will give the appropriate repeat command to Windows Media
Player.
Avi
To Htm
Creates an HTM file for each video file in a folder. Should work for
AVI, MPG, MOV, WMV, and more depending on client capabilities. It uses
two unusual approaches. First, it uses IE's <img
dynsrc=
tag for the video files. This causes the videos to be displayed just
like an image: raw with no player controls. Non-IE browsers fall back
to using the embed
tag
for the Media Player plugin (again with no controls). Of course, this
means I have to have some sort of browser detection script. But I
didn't want to use scripting! Luckily, I remembered IE's "conditional
coments" which class IE5 and newer in one group, and all
other
browsers in another group. Close enough!
Wav To Htm
Creates an
HTM file to match every multimedia file in a folder. Handles AVI. MPG,
MP3, or any file that can be played
with Microsoft's Media Player. The created HTM file has the usual
OBJECT / EMBED code to insure your file
plays in all browsers. This can be handy to insure multimedia files
stay in the browser and don't cause a download or spawn a separate
player.
Gallery
Browser
Think of it as a manually advanced browser-based slideshow where you
can preview thumbnails of all the images. The best part is you don't
have to create the web pages or the thumbnails. Just tell the script
(when it asks) where your folder of pictures is and it will create
"index.htm" and "select.htm" files which will allow you to browse all
the images in a framed setting. The HTM files that are created contain
relative links, so they'll work whether you upload them to your web
site or keep them on your hard drive.
Fli Player This script can be used as a command line or drag'n'drop FLI animation player. Actually, all the heavy lifting is done by a Java program written by Jörg Anders from http://rnvs.informatik.tu-chemnitz.de/~jan/FLI/FlicFile.html. I don't write Java, so I just compiled the source code and embedded the resulting class files in the script. The script's job is to extract the class files and create a web page on the fly. Then it launches Internet Explorer, displays the page, and cleans everything up afterwards. All you have to do is drop an FLI file on the script. Assuming you can find any FLI files.
|
|
Slurp
If you
find a web page (like the clipart collection at
http://www.kamsart.com/clipart/free-clipart-Navy.html) that has lots of
links on it -- and you want to download all the linked files, this will
help. Just supply the URL of the web page, the folder on your hard
drive where you'd like the files stored, and the file extension of the
files you're after. The script does the rest.
Gallery Thief This is a collection of several scripts that can grab all the images from popular image galleries. Many image galleries have so many pictures you just don't have time to locate, select, and download your favorites. It's easier to just download the lot overnight and sort them offline later. This is NOT a simple web site mirroring program. It ONLY downloads the JPG files (actually, files with mime types of "image/jpeg") and it puts them all in the same folder on your hard drive. To prevent name collisions (and help you remember where you got the pictures from), the files are typically given names that reflect their URL (but you can change the naming convention). If you have to quit, the script will pick up from where it left off when you start it up again. One big advantage of doing this with a script instead of with a "real" program is that scripts run invisibly (unless you say otherwise). You figure out how that might benefit you. On the other hand, if you make the script run in an "Open with Command Prompt" cscript DOS box, the script will give you a status display so you know how things are going.
Clipboard Download If you only want to grab a few links from a web page, it's easy to just do a right-click and save the linked content. But if you need to rename the downloaded files to prevent name collisions when downloading from several different web pages, it gets bothersome. This script allows you to copy a URL (web link) from browser, then run the script to automatically download and rename whatever the clipboard URL points to. Of course, there's a few options to let you select what folder you want the files stored in.Wget
Back in the days before broadband, if I tried downloading more than two
files at a time, my download speed per file would drop so low that
servers would drop me. I tried a few of the automatic download managers
and didn't like the
built-in
ads or the instability they caused. All I wanted was a simple
sequential
downloader. So I wrote a script. Here's how it works: You
drag
links
out
of your browser and drop them into a designated directory. You choose
the
directory (it can even be the desktop). The script
will
download the files associated with the links into another designated
directory.
Again, you choose the download directory. As the files are downloaded,
the shortcuts to the links you originally dragged are deleted. If you
run the script with WSCRIPT (right-click the script and
select "Open"), it runs totally invisibly. If you run it with CSCRIPT
(right-click
and select "Open with Command Prompt", it gives you a status display of
what it is doing. Your choice. If you have to turn off your computer
before your downloads are finished, the next time you start the script
(and point it to the appropriate folders), it will re-download any
partially downloaded files and continue until all your files are
downloaded. Now... Why the name Wget? Because originally
Windows
didn't have a decent download object. So I had to use a separate
utility named Wget.
Not being
particularly clever when it comes to names, I decided to name the
script after the utility that did all the hard work. The script has
since been rewritten to take advantage of the WinHttp object in Windows
2000 and XP. Wget is no longer needed, but I kept the
original script name.
Update
McAfee (Network
Associates) Antivirus
THIS SCRIPT HAS NOT BEEN UPDATED TO FOLLOW CHANGES TO THE MCAFEE WEB
SITE. If your antivirus is old enough that the automatic updater is
trying to
frighten you into buying something you don't need, disable the
auto-updater and use this script! If you have Windows 2000, XP, or
newer -- and if you've installed recent service packs -- then you
finally got yourself a decent scriptable HTTP download control. I use
that control
to locate and download the latest McAfee "SuperDAT" file.
Unfortunately, scripting has no fast way to save the downloaded file (a
pure script solution would take hours), so I use my open-source byte array control
to save the SDAT file to disk. To make things really simple, the byte
array control has been embedded in the script, so there is no need to
permanently install the control. Just run the script and it all happens
automatically. Just schedule the script to run once a week and you're
done. I know, adodb.stream could also have been used to save the binary
file, but not everybody has ado installed. FYI, I also made a pure
batch solution that uses FTP. If you're a network
administrator,
you might want want to read how to
download the
latest commercial update.
Update Symantec (Norton) Antivirus THIS SCRIPT HAS NOT BEEN UPDATED TO FOLLOW CHANGES TO THE SYMANTEC WEB SITE. All it took was a few minutes and the above McAfee "SDAT" script became a Symantec "intelligent updater" daily update script! Both do the same things: Find the web page that lists the most recent update, download that update, then run the update. Just to be complete, I also created a batch and FTP solution. Unlike the above McAfee script, this Symantec script has been rewritten to not use my custom byte array control. Which came with a surprise... Because I used the Microsoft "adodb.stream" object to save the "intelligent updater" file, my antivirus program now thinks the script has the "psyme" trojan in it. Rewriting (or encoding) the script to avoid the false virus warning would just make it harder for you to read. So I'll leave it to you to encode the script or tell your antivirus to trust/exclude the script.
Download Ftp This FTP download program doesn't require you to have any extra utilities. It automates the built-in FTP client that ships with all versions of Windows. It was written to allow me to make daily FTP downloads of a text data file over my company intranet. NT/XP/2000 users will have to modify the embedded FTP command line to point to the correct location of the FTP program.Get Web Page
This is actually a library of several different functions all with the
same name designed to download the text from a web page. You pick which
one you want and delete the rest. I have several CGI web pages on my
company
intranet that contain data I automatically download using these
functions.
Binary
Download
If you want to download something other than text over HTTP, it gets a
bit more complicated. Scripting isn't really designed to handle
"binary" files. But it can be done! Here I show the "correct" method
for doing it and two other very unusual methods for doing it. Stay away
from the unusual methods -- they are just for fun.
|
|
SFX
Convert any file into a self-extracting VBS file. When you run the VBS
file, the original file will be "extracted". That's useful enough. And
pretty handy. The reason I wrote
this is to allow packaging DLL helper files in with scripts that needed
them. And -- this script is an example! It needs a small OCX
file
to read binary files. Because nobody is likely to have that file, it's
been built into script. If you don't have the object already registerd
on your system, this script will create, register, and unregister it on
the fly. So look how I did it if you ever need to distribute a DLL or
OCX file with your script!
SHAR
Similar
to the above SFX scripts, but... different. More generic. More useful!
And two different versions! Batch and Scripting! Like the SFX scripts,
SHAR creates a self-extracting file. By choosing which version of SHAR
you run, you can create a VBS self-extractor or a DOS BATCH
self-extractor. Unlike
the SFX script, both versions of SHAR exclusively use ADO
instead of an embedded "helper" file to read binary files. That makes
the SHAR scripts a lot easier to understand and maintain! Another
difference is that while SFX only extracted a file to the script's
directory, the SHAR VBS version allows you to browse to your desired
extraction folder.
The SHAR BATCH version only extracts to the "current directory", but
that's the price you pay to be compatible with everything all the way
back to DOS version 6. Both versions of SHAR generate archives that are
optimized to stay under 80 columns
wide. As a result, the text from a SHAR archive (VBS or BAT) can be
copied and pasted
into the body of an email, then be copied and pasted back into a VBS or
BAT
file (as appropriate) on the receiving end. This effectively allows
file attachments
where attachments aren't allowed or where separate decoders may not be
available. FYI, the "shar" name of this script is taken from an old
UNIX command "shar", which stands for "shell archive". In other words,
an archive that can be extracted using nothing more than the "shell",
or built-in operating system commands. Which is exactly what these SHAR
scripts create.
SCEN
This is a
VBS only (no WSC scripts!) script encoder. Take a working script of
yours and drop it on SCEN. SCEN will turn it into a virtually
unreadable mess that will still run. If you aren't allowed to install
the genuine Microsoft script encoder -or- have to be backwards
compatible with older (Win95 and original Win98) versions of scripting
-or- only need casual protection from prying eyes -or- need to change
your script so it doesn't contain sensitive words, then SCEN might be
handy. SCEN will create a script with lots of hex data, a
bare-bones hex decoder, and the obligatory "ExecuteGlobal" command.
Thanks to ExecuteGlobal, your decoded file is run directly from memory
and is never written to the disk. Pretty darned simple. And your script
will still work! It even works if you run it through the encoder
several times.
Url Encode Convert a recognizable URL into an ugly-looking encoded mess. A mess that still works as a valid URL! Great for when you need to give someone a URL you don't want them recognizing. Or just to mung up text. For example, it can help convert http://google.yahoo.com/bin/query?p=ericphelps.com into http://google.yahoo.com/bin/query?p=%65%72%69%63%70%68%65%6C%70%73%2E%63%6F%6D
UrlEncode (online) Online URL encoding because I needed it available on my phone.
Url Decode Allows you to see what URL someone is trying to hide from you.
Rot13 Just rotates letters. A becomes N, B becomes O, and so on. Netscape mail has built-in support for viewing ROT-13 text, but darned if I could find an easy way to encode text.
Decode
UU
Decode
Just playing around. When I get the encode and decode both complete,
I'll move it into the above Decode.htm file. Meanwhile, you can use
this to decode UU text.
|
|
Wiki Uploader If you have a script that creates text for a Wiki page (like to post tables on a Wiki at work), this script illustrates how to automatically upload it. Actually, this script uses http://test.wikipedia.org/wiki/Sandbox as the upload target, so you can play with it. It will be up to you to edit the script to point to your Wiki. NOTE: This script is intended for Intranet (company network) use only. It would be just plain stupid and very rude to use it on an Internet Wiki.
Make Ftp Script I have too many web pages to keep up with. I may modify a dozen files in as many directories over a period of days before I upload the changes. And then -- oops. Which ones did I modify or create since my last upload? This searches for modified files (based on the archive bit), then creates an FTP upload script. It doesn't actually upload anything, it just creates a script batch file. Running the batch file will do the actual upload. It includes an undo batch file to reset the archive bits in case you change your mind. Using the archive bit is very appropriate because you don't need to back up anything that has been uploaded to the web (The web is your backup!). NT/XP/2000 users will have to modify the embedded FTP command line to point to the correct location of the FTP program.
Ftp Upload No interaction version of the above script. This one will actually upload all modified files in and under a specified directory in one shot. Automatic undo if it can't connect to the FTP server. Log files are always kept of action and results. Can be run visibly or invisibly. So -- after you get comfortable with the above script, you switch to this one. Edit seven values (Simple things like strRemoteSite = "ftp.calweb.com") and you're home free! Use this script to make life easier for yourself. NT/XP/2000 users will have to modify the embedded FTP command line to point to the correct location of the FTP program.
Ftp File Upload Very basic version of the above script. Again with no user interaction, but it only uploads files you designate, and it puts them where you designate. You have to build the source and destination file names into the code. This is more appropriate for giving to "content creators" that are only responsible for creating or updating a few files. To simplify things, this script does not check for or change archive bit status. This is really little more than a template that will require considerable rewriting on your part. And honestly, since you are ignoring the archive bit, you could simplify things even further by writing your own FTP batch file rather than having the script do it for you.
Web Server Upload CGI This one is HTTP POST upload. I was frustrated over the lack of a simple file upload capability in IIS5. I tried Microsoft's NT4 upload acceptor for about ten minutes before I was overcome by the smell. I was too cheap to pay for a good commercial upload control, too lazy to invest time in the BinaryRead method, and too vain to allow someone's else's free upload control to display their logo on my web page. So I wrote my own.
|
|
Access.hta Internet Explorer only. Simple table and query viewer for Access 2000 for people who don't have Access 2000. You don't need Access or Office on your computer! Microsoft gives away the database engine, and writing a simple front-end isn't all that hard. Tables or queries with more than about a couple hundred records take way too long to display, but hey -- I said it was simple!
Odbc.hta
Internet
Explorer only Simple database and table viewer for
ODBC
databases.
Heck, you can even turn a collection of ordinary text data files into a
complete ODBC database you can query! Think of this as a poor
substitute
for the awesome and free WinSQL
program. But if you have a locked-down machine or you need a quick,
free,
open-source viewer, (or you just want to steal my sample code), this
might
help you out. Rename this file with an HTA file extension if your
default browser isn't IE or if you want to bypass the ActiveX dialog.
Mdb To Txt
Converts Microsoft Access queries or tables into plain text. Originally
written so the output text could be converted into Palm DOC format or
linked
into another database. If you use tabs as the separator characters, the
resulting tab-delimited file can be given an XLS file extension and
will
open fine with Excel on most systems. Which means you can also consider
this to be an automatic Access to Excel converter. The script is
hard-coded
to use Jet for Access 97 (change the reference to "DAO.DBEngine.35" to
match your DAO version). Pass it an MDB file name, query or table name,
output text file name, and formatting data (comma-separated max field
lengths
and desired output field separators):
Mdb 2 Pdb
Lets you carry Microsoft Access queries or tables in your Palm OS
device.
Hard-coded to use Jet for Access 97 (change "DAO.DBEngine.35" to
"DAO.DBEngine.36"
if you have Access 2000). Pass it an output PDB file name, an output
document
name, MDB file name, query or table name, and (if the query requires
it)
a single parameter:
You need the free Palm
DB
program on your Palm and the conversion utility "csv2pdb.exe" on your
PC
in the PATH (or in the current directory).
Excel To Tab
I don't know. Once you see how to read an Excel file with scripting,
you just read it. If you need tab-delimited text, you must need it for
something else. Like, ummm, maybe linking the data into a database
without using the slow Excel ODBC.
|
|
Miscellaneous
Snippets A collection of my
boilerplate VBScript
functions.
HOSTS File
Utilities
If
you use your HOSTS file to block bad sites, you might enjoy a few
scripts and batch files I wrote to help you manage your HOSTS file.
SNPP
and SMS A
cute way to send a text message to a cell phone or pager from Windows
2000 or newer. It may not work on all carriers, but it works for Nextel!
Activity
If you have a forced screensaver, logout, or workstation lock policy,
this simple script can stop it from happening! This script hits
the "shift" key once every ten minutes. That's too easy!
Netstat Mostly just a GUI wrapper for the command-line NETSTAT program. The value-added is that it refreshes every two seconds and only counts from when the program is started.
Brute Force Dictionary Generator This script will create a dictionary useful for brute-force password attacks. One word will be placed on each line. You can specify how big the password is as long as it doesn't exceed 8 characters. All 95 keyboard characters are used by default. If you want to exclude certain letters, numbers, or punctuation from the generated words, you'll need to edit the script. WARNING: The files generated by this script get real big, real fast. For example, with 95 possible characters and a 4 character password, you get a 500MB file. If you're foolish enough to try to make an 8-character password list, there won't be enough disk space no matter who you are. The huge file size explains why nobody offers dictionary files like these for download.Windows 2000 Performance Monitor Ibrahim Niazy shows how to use Windows Scripting to organize the reams of data the Win2K performance monitor spits out.
Register and unregister your script as a right-click option on folders. Stephen Webster Cocks <webster@softcom.net> gives us an example of the right way to distribute scripts. Running it with no arguments automatically installs it as a right-click option on folders (with lots of nice sample registry code). If it is already installed, running it with no arguments will uninstall it. The actual point of the script is to create a shortcut to the selected folder. While you may not need that, you will want to pay attention to the concept of building install and uninstall capabilities into your scripts! Unfortunately, McAfee with heuristics enabled will falsely detect a generic unknown virus in this code. My feeling is that it's unavoidable because the script copies itself into the Windows directory and makes registry changes. Good luck modifying the code to avoid the false virus hit if you plan to redistribute code like this. Sorry!
Determine sizes of all subdirectories Drag a folder onto this script (or install it as a right-click option) and it will tell you the size of all subfolders. Great for determing which folders can get backed up to a CD. I wrote this because under Win95, getting the properties for a folder to determine it's size fails -- it rolls over and starts over when it hits 2 gigabytes. Because it actually adds the file sizes of every file in every subdirectory, it isn't particularly fast, but at least it is accurate! Displays results as a pop-up box, but falls back to displaying as a text file if there is too much data to fit in a simple display box.
Find the CDROM A script made to be used from a batch file -- but you can simplify it to stay in the scripting world. Finds the first drive letter that corresponds to a CDROM drive.
PrintWebPageWithWord Illustrates how to automate Word to print a web page. My web page. Well, until you modify the code!
MakeAndRunBatchFile Shows how to create, run, wait for, and delete a batch file from scripting.
UserIn Shows how to create, run, wait for, and delete a script from a batch file. In a perverse twist, the created script has to in turn create a batch file of it's own in order to communicate results back to the original batch file. Why bother? Because it provides a really nice way to get user input in a batch file!
YC Windows 2000/XP only One thing I missed when I got moved from Win95 to Win2000 was the ability to single-step my batch files with the "command /y /c" command. Unfortunately, Win2K doesn't seem to have a way to single-step batch files. Not even if you try using an old copy of Win95 command.com! So I wrote this script. It works by constructing a special debug version of your batch file, launching it, then putting everything back to normal after the batch file finishes. It isn't the same as what I could do in Win95 (it won't single-step a "call"ed batch file), but it beats the heck out of watching programs crash and close before you can analyze things! It also adds "//x" to the command line for scripts to launch them with the debugger. Just drop a batch file on the script and start stepping through.
Compare Someone asked how to compare two numbers from a batch file. As long as both numbers have the same number of digits, you could "echo" them into a file, "sort" the file, then use "fc" to see if the file changed. But what fun is that? That takes six lines of batch code. By using this script, you drop down to three lines of batch code AND you can use any operator (>, >=, =, <=, <) and you don't have to have same-length numbers (you can properly compare 003 and 4). So what if I used 60 lines of scripting to accomplish this trivial task?
Send Email Self-defense information to help you (and me) out because I get asked how so often!
|
|
Find
Your IP Address
If you want to find the IP
address of the computer your script is running on, this ActiveX DLL can
help. Even better, do
it
natively.
Read Binary Data
An ActiveX DLL needed if you want your scripts to be able to read
binary
data (like a GIF picture or Excel file).
Convert
Byte Array to
String An OCX that converts
byte arrays to strings
2 to 3 times faster than native VBScript.
|
|
XBM Page Counter A CGI script or ASP (your choice) that shows a single XBM graphic containing multiple digits (instead of a separate graphic for each image) representing how many times your web page has been hit. Hit count data is stored in an Access database. The advantage of XBM graphics is that it is trivial to splice several separate digits into a single graphic. Maybe you've never heard of the XBM graphic format, but your browser probably has!
ChatCGI A VBS chat CGI. Pretty straightforward. Displays the last 50 comments, allows users to enter new comments, and stores everything in an Access database via DAO.
Web
Server Upload CGI
Yes, this is the same item I "cross-posted" above in the FTP upload
section.
It's there because it's an upload program, but it's here because it isn't
FTP. I was frustrated over the lack of a simple file upload capability
in IIS5. I tried Microsoft's NT4 upload acceptor for about ten minutes
before I was overcome by the smell. I was too cheap to pay for a good
commercial
upload control, too lazy to invest time in the BinaryRead method, and
too
vain to allow someone's else's free upload control to display their
logo
on my web page. So I wrote my own.
Lost? Look at the site map.
Bad links? Questions? Send me mail.