Reader to Reader - Scripting Solutions - 01 May 1999


\[Editor's note: Email your scripting solutions (400 words or less) to R2R at [email protected]. Please include your script and phone number. We'll edit submissions for style, grammar, and length. If we print your contribution, you'll get $100.\]

Not long ago, my company's CEO started sending encouraging email messages to everyone at the end of the day. After talking to her about alternatives, I implemented a short script in the users' logon script so that users automatically receive the Message of the Day when they log on to the network.

The DBDLogon.vbs script that Listing 1 shows is straightforward. The script reads text from a text file (message.txt) and sends the file's contents to a message box for the user to view. The text file is on a secure file server so that users can't alter the message.

This solution, which I wrote in Visual Basic Script (VBScript), requires that all users have the Windows Scripting Host (WSH) installed. You also need to include the following line in each domain controller's network logon script:

wscript.exe \\server\netlogon   DBDLogon.vbs

In this line, server is the name of the server containing the DBDLogon.vbs script.

Scripts Determine How Users Occupy Disk Space

I manage a shared disk that contains the home directories of 100 employees. Although I don't use a quota system, I still need to determine how users occupy the disk space, because no matter how big the disk is, the users tend to fill it up. Specifically, I need to determine the following:

  • How much disk space each user occupies
  • How many temporary files are in each home directory
  • How many empty files and small files (1B to 1KB) exist

I created the Stat package to find out this information. The Stat package consists of one primary script and three secondary scripts, which I wrote in JScript (.js) in the WSH environment. I divided the scripts into two levels, because collecting statistics for a large file system is a lengthy operation. I usually schedule the primary script to run on my servers at night, because this script is the most time-consuming. In the morning, I run the secondary scripts so that I can view the statistics. The four scripts are

  • StatDisk.js, the main script that scans the specified files and subdirectories. This script creates a text file containing information about the files and folders it scans. The other Stat scripts use this text file to produce statistics.
  • StatDir.js, a secondary script that groups disk-space allocation by directory. Together, StatDisk.js and StatDir.js provide statistics about how much disk space each user occupies.
  • StatSize.js, a secondary script that groups disk-space allocation by file size. Together, StatDisk.js and StatSize.js provide statistics about how many empty and small files exist.
  • StatExt.js, a secondary script that groups disk-space allocation by file extensions. Together, StatDisk.js and StatExt.js provide statistics about how many temporary files exist in each home directory.

You can find these four scripts on the Win32 Scripting Journal Web site. To run the StatDisk.js primary script, you use the command

StatDisk /SOURCE path /DEST filename

in which path specifies the directory to scan and filename specifies the name of the text file that will contain the scan information. For example, if you want to run StatDisk on C:\Users and put the scan information in stat.txt, you type

StatDisk /SOURCE C:\Users /DEST stat.txt

To run the StatDir.js secondary script, you use the command

StatDir /SOURCE filename /DEST filename

In this code, you specify the filename of the text file containing the scan information as the source and the filename of the text file that will contain the statistics as the destination. For example, if you want StatDir.js to provide statistics about the C:\Users scan information and you want the statistics in the ext.txt file, you type

StatDir /SOURCE stat.txt /DEST ext.txt

Figure 1 contains an example of the output that StatDir.js generates. The first column in the example output shows the directory nesting level.

The code to run StatSize.js is similar to the code to run StatDir.js. However, you can use the optional /SHORT switch

StatSize /SOURCE filename /DEST filename \[/SHORT\]

The /SHORT switch tells StatSize.js to exclude filenames in the output. You use this switch when you don't need the filenames or when the output will contain many filenames. For example, to obtain the example output you see in Figure 2, I included the /SHORT switch. If I hadn't used this switch, the output would have listed the filenames of the 22 empty files and the 270 small files.

You can also use the /SHORT switch with the command to run StatExt.js:

StatExt /SOURCE filename /DEST filename \[/SHORT\]

Figure 3 provides example output for StatSize.js. Because I didn't use the /SHORT switch, the output includes the filenames.

—Alessandro Iacopetti
[email protected]

Automate Your Network Printer Setup

If you want an easy, efficient way to automate your Windows NT network printer setup, try the PrinterInstall.bat script in Listing 2. You can add as many network printers to this batch file as you need, specifying the appropriate server_name and printer_share_name information. You can distribute this script to users by attaching it to an email or including it in the logon script.

The script begins by starting the network printer. If the NT system discovers that this network printer is already installed on users' machines, the script opens the Printer Monitor window. If the NT system discovers that this network printer isn't installed on users' machines, the script asks users whether they want to install the printer. If the users agree to the installation, the NT system installs the printer. When the installation finishes, all Printer Monitor windows close automatically.

My company's network has more than 15 printers. The PrinterInstall.bat script has saved the company many man-hours.

—David Volokh
[email protected]

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.