Updating the system path using Windows Script Host

On a recent business trip, I needed to add the full path to Microsoft Office and Lexis-Nexis CompareRite into the system path. (All workstations were running the French edition of Windows 2000.) Doing this manually – finding the installation path for the applications (since I wasn’t sure if all installations were to the same location on the local hard drives), then manually pasting or typing the paths into the System control panel – was too time-consuming for me, so I wrote a script to do it.

The Windows Script Host (WSH) engine is included with Windows 2000, so I wrote a WSH script using VBScript to do the necessary work:

Read the current system path from the registry.
Read the path to Microsoft Office from the registry.
If the Office path is not already in the system path, append it.
Read the path to CompareRite from the registry.
If the CompareRite path is not already in the system . . .

→ Read More: Updating the system path using Windows Script Host

Using the FOR command to copy files listed in a text file

A coworker asked me for a script. Here’s the request:

… would want to copy all files on this list [an attached text document] to another location (doesn’t really matter where for now). All are currently located in \\server\share\folder. The path in the new location should begin with the part after “folder”…

In a nutshell, here is the high-level description of what the script must do:

Given a text file which provides a list of files, copy the files from a fixed source to a fixed destination, recreating the directory trees on the destination. A simple file copy won’t work because there may be files in the source folders which should not be copied.

Sample content of the text file is:

client\CD120\Samarai Legends\Drafts\drafts folder.txt
client\CD120\Samarai Legends\Inbox\Legends.doc
client\CD120\Bushido Warriors\Inbox\Warrior Code.doc

The solution to this is to make a simple batch file that parses the content of the text file, generating the appropriate xcopy command to copy the file. We’ll call the batch file xcopylist.bat; its one line of content is . . .

→ Read More: Using the FOR command to copy files listed in a text file

Moving a FrontPage Web site to a non-FrontPage Web site

For a web application I am working on, there are two Web sites – a development site and a production site. Both reside on the same server. Development is done using Microsoft Visual InterDev, so to connect to the development site, I have FrontPage extensions installed. (I also integrate with Microsoft Visual SourceSafe, but that’s meaningless to this discussion.)

Moving files from the development environment to the production environment usually entails manual copying, because I do not have FrontPage extensions installed on the production site (for obvious reasons; I don’t really need them!). I finally found a way to do it – the “old-fashioned” way – using a simple command: XCOPY.

XCOPY, which has been a part of Microsoft’s command shell (also known as DOS prompt) for years, copies files from a source to a destination with a wealth of options – most important for me, the ability to copy changed files only and to exclude files and folders.

First, you need an exclusions . . .

→ Read More: Moving a FrontPage Web site to a non-FrontPage Web site

Exporting directories to delimited text files

A coworker of mine needed some way to get a list of all files in a directory (and its subdirectories) in a delimited text file. Specifically, they needed a pipe-delimited text file with the following fields:

folder path (the absolute path to the folder containing the file)
modified date
modified time
size, in bytes
file name

The solution was a VBScript using Windows Scripting technologies. It’s rather simple, utilizing the Scripting.FileSystemObject object. We retrieve the current directory using the GetFolder() function, which returns a Folders collection (i.e., a collection of Folder objects). This object is passed as a parameter to the ParseFolder() function in our script.

The ParseFolder() function gets the data from each File object in its Files collection and outputs it to a pipe-delimited text file (called diraudit.txt. It then calls itself (a recursive function) for each Folder object in its Folders collection. The recursion takes care of all the subsequent subfolders.

The actual code of the script, which I named diraudit.vbs, follows.

Option Explicit

Const ForWriting = . . .

→ Read More: Exporting directories to delimited text files

Running a Windows NT Domain / Active Directory Audit

Getting an audit of your IT environment is incredibly useful. When you consider an audit from a security perspective – in the Windows NT domain or Active Directory model – there are a few items of significant importance: domains, users, groups, computers, and services.

The first step in conducting an audit is discovery – find out what’s out there. Fortunately, we have a great scripting tool for this: ADSI (Active Directory Services Interface). ADSI can pull the information for us, but to utilize it, we need to store it somewhere – such as in a SQL database.

To save you the trouble of figuring this out, below is a (rather long) script which uses ADSI to poll your network and store data into text files. To run it successfully, you must have at least query access to your entire directory. (The script has been tested on an NT 4.0 domain and on an Active Directory site.) The script queries each domain, obtaining . . .

→ Read More: Running a Windows NT Domain / Active Directory Audit