Do you have a scripting-related question or problem? You can send your question or problem to firstname.lastname@example.org.
Do the names of script variables have some relevance, or are they purely arbitrary?
You can use whatever name you like for a variable. However, the consensus is to use a prefix with a descriptive name.
The prefix, which represents the type of data, typically contains one lowercase character or three lowercase characters. Commonly used three-character prefixes include
- str = String
- int = Integer
- bol = Boolean
- obj = Object
- ads = ADSI object
- app = Application object
- wsh = WSH object
- arr = Array
- ado = ADO object
- fso = FolderSystemObject
- fil = File object
- fol = Folder object
- lgn - Long Integer
- sgl = Single precision value
- dbl = Double precision value
In the descriptive name, you typically capitalize the first letter of each word but you don't put hyphens between words. (Typically, variable names are case-insensitive.) For example, you can name a string variable strMyPassword.
In Windows Scripting Host (WSH), you can create a shortcut, but how can you read the properties of an existing shortcut?
You can't. The WSH object model control (wshom.ocx) doesn't expose wshShortcut as a full automation object. You can expose wshShortcut only through wshShell.CreateShortcut.
How can I use WSH to write a script that checks the size of Windows NT and Windows 95 files and deletes those files that are larger than a specified size?
Listing 1 contains an example of how you might use WSH, VBScript, and the Scripting Runtime Library's FileSystemObject to check and delete files. You begin the script by declaring the variables and defining a constant that specifies the maximum file size. Although this script sets the constant's value to 1MB, you can change the constant's value to meet your needs.
Next, you initialize strFileSpec to the target filename, which you customize. You then create a reference to FileSystemObject, which you subsequently use to create a reference to the target file. You use the target file reference to access the File object's Size property and Delete method. The WScript.Echo statement displays the file's current size in megabytes, kilobytes, and bytes.
You use the If...Then statement to compare the file's size in bytes to the constant you defined earlier. If the file size is greater than 1MB, you delete the file.
How can I create an NT shell script that deletes files with a date older than MMDDYY from a directory?
To delete files by date, you need to install the Microsoft Windows NT Server 4.0 Resource Kit's Robocopy utility. Robocopy has a switch that lets you specify whether you want to copy or move files that are older than a certain age. You then take these steps:
- Set up a directory in which to put the old files that you want to delete. Name the directory OldFiles or a similar intuitive name. Robocopy will move users' old files into this OldFiles destination folder.
- ;Write a script that first deletes all the files and folders in the OldFiles folder and then calls Robocopy. Listing 2 contains a script that you can adapt. In your script, have Robocopy move all the files that are older than a specified number of days (e.g., 120 days) or a specified date (e.g., 070199) from the source directory to the OldFiles folder. Robocopy automatically clears the source area of any old files, and you can use the /move switch instead of the /mov switch to clear any empty directories.
- Schedule the script to run at a specified interval with the Net Use command.
Keeping users' old files in the OldFiles folder until the next scheduled deletion run rather than immediately deleting them can save you work down the road. If users need a file that Robocopy removed, you can restore the file from the OldFiles folder rather than from the backup tape.
Robocopy is powerful and can do real damage if you get the switches wrong. However, if you use Robocopy carefully, it will become another valuable addition to your NT toolkit.
In "An ADSI Primer, Part 5: Using ADO to Script Fast ADSI Searches" (May 1999), Alistair G. Lowe-Norris discusses the ADO database connector for Active Directory Service Interfaces (ADSI). Where can I obtain this ADO OLE DB connector?
You can find the ADO OLE DB connector on the Microsoft Developer Network (MSDN). Go to http://msdn.microsoft.com/developer/ sdk/platform.asp, and select MDAC 2.1 (including ADO, ODBC, and OLE DB). Make sure that you have the most recent copy of Microsoft Data Access (MDAC).