Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Databases are especially useful if you have scripts whose arguments might vary each time the script is run. For example, you might have a script that backs up a separate set of computers each day. Although this information can be stored in a text file, you would need to parse the entire text file each time the script ran, picking out the computers of interest. By contrast, you can construct a database query that will retrieve only the computers scheduled to be backed up on a given day. This approach is more efficient than reading through and parsing a text file.
Table 17.1 shows a simple database listing computer names and the day of the week each computer is scheduled for a full backup.
Table 17.1 Sample Backup Schedule Database
ComputerName | BackupDay |
---|---|
Server1 | Monday |
Server2 | Wednesday |
Server3 | Friday |
Server4 | Monday |
To create a script that runs against the appropriate computers on the appropriate days, you simply include code that limits data retrieval to a specific day. For example, this SQL query returns only the set of computers designated for backup on Thursday:
"SELECT * FROM Computers WHERE BackupDay = 'Thursday'
"
By including additional fields within the table, you can construct an all-purpose database that contains the arguments for many of your scripts. For example, additional fields might indicate the date to back up and clear event logs, the dates and times for performance monitoring, or the list of services to be checked on a routine basis.
Note
Listing 17.3 contains a script that retrieves arguments from a database. (The database and the database table must exist before this script can run.) To carry out this task, the script must perform the following steps:
These constants will be used to configure the CursorLocation, CursorType, and LockType for the connection.
The Connection object makes it possible for you to issue queries and other database commands.
The Recordset object stores the data returned from your query.
Be sure to append a semicolon (;) to the Data Source Name.
The Open method requires four parameters:
This query returns a collection consisting of all the services installed on the computer.
Listing 17.3 Retrieving Arguments from a Database
|
|
Send us your feedback | « Previous | Next » |