Microsoft® VBScript Step by Step

Book description

Get guidance from a well-known scripting expert—and teach yourself the fundamentals of Microsoft Visual Basic Scripting Edition (VBScript). This tutorial delivers hands-on, self-paced learning labs to help you get started automating Microsoft Windows administration—one step at a time.

Discover how to:

  • Manage folders and files with a single script

  • Configure network components with Windows Management Instrumentation

  • Administer users and groups using subroutines and Active Directory Service Interfaces (ADSI)

  • Design logon scripts to configure and maintain user environments

  • Monitor and manage network printers

  • Back up and edit the registry—avoiding common pitfalls

  • Handle errors and troubleshoot scripts

  • Simplify administration for Microsoft Exchange Server 2003 and Internet Information Services 6.0

  • Includes a CD featuring:

  • All practice exercises

  • 100+ sample scripts to adapt for your own work

  • For customers who purchase an ebook version of this title, instructions for downloading the CD files can be found in the ebook.

    Table of contents

    1. Acknowledgments
    2. Introduction
      1. A Practical Approach to Scripting
      2. Is This Book for Me?
      3. Outline of This Book
        1. Part I: Covering the Basics
        2. Part II: Basic Windows Administration
        3. Part III: Advanced Windows Administration
        4. Part IV: Scripting Other Applications
        5. Part V: Appendices
      4. Finding Your Best Starting Point
      5. About the Companion CD
        1. Installing the Practice Files on Your Computer
        2. Uninstalling the Practice Files
      6. System Requirements
        1. Technical Support
    3. I. Covering the Basics
      1. 1. Starting from Scratch
        1. Running Your First Script
          1. Header Information
            1. Option Explicit and Dim
            2. On Error Resume Next
          2. Reference Information
          3. Worker Information
          4. Output Information
        2. Enhancing Your Script
        3. Modifying an Existing Script
          1. Modifying the Header Information
          2. Modifying the Reference Information
          3. Modifying the Worker Information
          4. Modifying the Output Information
        4. Exploring a Script: Step-by-Step Exercises
        5. One Step Further: Customizing an Existing Script
          1. Scenario
            1. Step-by-Step Instructions
            2. Chapter 1 Quick Reference
      2. 2. Looping Through the Script
        1. Adding Power to Scripts
        2. For Each...Next
          1. Header Information
            1. Defining Constants
          2. Reference Information
          3. Worker Information
        3. For...Next
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. Do While...Loop
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        5. Do Until...Loop
          1. Worker and Output Information
        6. Do...Loop
        7. While...Wend
        8. Creating Additional Objects
        9. Using the For Each...Next Command Step-by-Step Exercises
        10. One Step Further: Modifying the Ping Script
          1. Chapter 2 Quick Reference
      3. 3. Adding Intelligence
        1. If...Then
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        2. If...Then...ElseIf
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        3. If...Then...Else
        4. Select Case
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
            1. funComputerRole function
        5. Modifying CPUType.vbs Step-by-Step Exercises
        6. One Step Further: Modifying ComputerRoles.vbs
          1. Scenario
            1. Part A
            2. Part B
            3. Chapter 3 Quick Reference
      4. 4. Working with Arrays
        1. Passing Arguments
        2. Command-Line Arguments
          1. Making the Change
          2. Running from the Command Prompt
          3. No Arguments?
          4. Creating a Useful Error Message
        3. Using Multiple Arguments
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. Tell Me Your Name
          1. Reasons for Named Arguments
          2. Making the Change to Named Arguments
          3. Running a Script with Named Arguments
        5. Working with Arrays
        6. Moving Past Dull Arrays
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
          4. What Does UBound Mean?
        7. Two-Dimensional Arrays
          1. Mechanics of Two-Dimensional Arrays
          2. Header Information
          3. Reference Information
          4. Worker and Output Information
            1. Using the For...Next Construction
            2. Assigning Values to Each Element
        8. Passing Arguments Step-by-Step Exercises
        9. One Step Further: Building Arrays
          1. Chapter 4 Quick Reference
      5. 5. More Arrays
        1. Strings and Arrays
        2. Parsing Passed Text into an Array
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        3. Parsing Passed Text
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        4. Working with Dictionaries
          1. Understanding the Dictionary Object
            1. Compare Mode
          2. Adding Items to the Dictionary
        5. Using Basic InStr Step-by-Step Exercises
        6. One Step Further: Creating a Dictionary
          1. Chapter 5 Quick Reference
    4. II. Basic Windows Administration
      1. 6. Working with the File System
        1. Creating the File System Object
        2. File It Under Files
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        3. File Properties
        4. File Attributes
          1. Implementing the Attributes Property
          2. Setting File Attributes
        5. Creating Files
        6. Writing to a Text File
          1. Determining the Best Way to Write to a File
          2. Overwriting a File
        7. Verifying a File Exists
        8. Creating Files Step-by-Step Exercises
        9. One Step Further: Creating a Log File
          1. Chapter 6 Quick Reference
      2. 7. Working with Folders
        1. Working with Folders
          1. Creating the Basic Folder
          2. Creating Multiple Folders
          3. Header Information
          4. Reference Information
          5. Worker Information
          6. Output Information
        2. Automatic Cleanup
          1. Deleting a Folder
          2. Deleting Multiple Folders
        3. Binding to Folders
          1. Does the Folder Exist?
        4. Copying Folders
        5. Moving Folders
        6. Creating Folders Step-by-Step Exercises
        7. One Step Further: Deleting Folders
          1. Chapter 7 Quick Reference
      3. 8. Using WMI
        1. Leveraging WMI
        2. Understanding the WMI Model
        3. Working with Objects and Namespaces
        4. Digging Deeper
        5. Listing WMI Providers
        6. Working with WMI Classes
          1. Viewing Properties
          2. Working with WMI Methods
        7. Querying WMI
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        8. Retrieving Hotfix Information Step-by-Step Exercise
        9. One Step Further: Echoing the Time Zone
          1. Chapter 8 Quick Reference
      4. 9. WMI Continued
        1. Alternate Ways of Configuring the WMI Moniker
        2. Accepting Defaults
          1. Reference Information
          2. Worker and Output Information
            1. Working with Multivalue Properties
        3. Moniker Security Settings
          1. WbemPrivilege Has Its Privileges
        4. Using the Default WMI Moniker Step-by-Step Exercises
        5. Invoking the WMI Moniker to Display the Machine Boot Configuration
        6. Including Additional Security Permissions
        7. One Step Further: Using Win32_Environment and VBScript to Learn About WMI
          1. Chapter 9 Quick Reference
      5. 10. Querying WMI
        1. Tell Me Everything About Everything!
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        2. Selective Data from All Instances
        3. Selecting Multiple Properties
        4. Choosing Specific Instances
        5. Using an Operator
        6. Where Is the Where Clause?
        7. Writing an Informative WMI Script Step-By-Step Instructions
        8. One-Step-Further: Obtaining More Direct Information
          1. Chapter 10 Quick Reference
    5. III. Advanced Windows Administration
      1. 11. Introduction to Active Directory Service Interfaces
        1. Working with ADSI
          1. Reference Information
            1. ADSI Providers
          2. LDAP Names
          3. Worker Information
            1. IADsContainer
            2. Binding
        2. Output Information
        3. Creating Users
          1. Reference Information
          2. Worker Information
          3. Output Information
        4. Creating OUs Step-by-Step Exercises
        5. One Step Further: Creating Multi-Valued Users
          1. Chapter 11 Quick Reference
      2. 12. Writing for ADSI
        1. Working with Users
          1. General User Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        2. Modifying the Address Tab Information
          1. Reference Information
          2. Worker Information
            1. Staying Put
          3. Output Information
          4. Modifying Terminal Server Settings
        3. Deleting Users
        4. Deleting Users Step-by-Step Exercises
        5. One Step Further: Using the Event Log
          1. Chapter 12 Quick Reference
      3. 13. Using ADO to Perform Searches
        1. Connecting to Active Directory to Perform a Search
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        2. Creating More Effective Queries
        3. Searching for Specific Types of Objects
          1. Reference Information
          2. Output Information
        4. What Is Global Catalog?
        5. Creating an ADO Query into Active Directory Step-by-Step Exercises
        6. One Step Further: Controlling Script Execution While Querying Active Directory
          1. Chapter 13 Quick Reference
      4. 14. Configuring Networking Components
        1. WMI and the Network
          1. Making the Connection
          2. Header Information
          3. Reference Information
          4. Worker and Output Information
        2. Changing the TCP/IP Settings
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        3. Merging WMI and ADSI
        4. Win32_NetworkAdapterConfiguration
        5. Using WMI to Assign Network Settings Step-by-Step Exercises
          1. Instructions
        6. One Step Further: Combining WMI and ADSI in a Script
          1. Chapter 14 Quick Reference
      5. 15. Using Subroutines and Functions
        1. Working with Subroutines
          1. Calling the Subroutine
          2. Creating the Subroutine
        2. Creating Users and Logging Results
        3. Header Information
          1. Reference Information
          2. Worker Information
          3. Output Information
        4. Working with Functions
        5. Using ADSI and Subs, and Creating Users Step-by-Step Exercises
        6. One Step Further: Adding a Logging Subroutine
          1. Chapter 15 Quick Reference
      6. 16. Logon Scripts
        1. Working with IADsADSystemInfo
        2. Using Logon Scripts
        3. Deploying Logon Scripts
          1. Header Information
          2. Reference Information
            1. Using the WshNetwork Class
          3. Worker Information
        4. Output Information
        5. Adding a Group to a Logon Script Step-by-Step Exercises
        6. One Step Further: Adding Logging to a Logon Script
          1. Chapter 16 Quick Reference
      7. 17. Working with the Registry
        1. First You Back Up
        2. Creating the WshShell Object
          1. Setting the comspec Variable
          2. Defining the Command
        3. Connecting to the Registry
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. Unleashing the Power of the StdRegProv Class
        5. Creating Registry Keys
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        6. Writing to the Registry
        7. Deleting Registry Information
        8. Reading the Registry Using WMI Step-by-Step Exercises
        9. One Step Further: Creating Registry Keys
          1. Chapter 17 Quick Reference
      8. 18. Working with Printers
        1. Working with Win32_Printer
        2. Obtaining the Status of Printers
          1. Header Information
          2. Reference Information
          3. Worker Information
          4. Output Information
        3. Creating a Filtered Print Monitor
          1. Reference Information
          2. Output Information
        4. Monitoring Print Queues
          1. Worker and Output Information
        5. Monitoring Print Jobs Step-by-Step Exercises
        6. One Step Further: Checking the Status of a Print Server
          1. Chapter 18 Quick Reference
    6. IV. Scripting Other Applications
      1. 19. Managing IIS 6.0
        1. Locating the WMI classes for IIS 6.0
          1. CIM_ManagedSystemElement
          2. CIM_Setting
          3. IIsStructuredDataClass
          4. CIM_Component
          5. CIM_ElementSetting
          6. Using MicrosoftIISv2
        2. Making the Connection
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        3. Creating a Web Site
          1. Header Information
          2. Reference Information
          3. Worker and Output Information
        4. Backing Up the Metabase Step-by-Step Exercises
        5. One Step Further: Importing the Metabase
          1. Chapter 19 Quick Reference
      2. 20. Working with Exchange 2003
        1. Working with the Exchange Provider
        2. Connecting to MicrosoftExchangeV2
        3. The Exchange_QueueSMTPVirtualServer Class
        4. Header Information
          1. Reference Information
          2. Worker Information
          3. Output Information
        5. Exchange Public Folders
        6. Exchange_FolderTree
        7. Using the Exchange_Logon Class Step-by-Step Exercises
        8. One Step Further: Using the Exchange_Mailbox Class
          1. Chapter 20 Quick Reference
      3. 21. Troubleshooting WMI Scripting
        1. Identifying the Problem
          1. Spotting Common Sources of Errors
        2. Testing the Local WMI Service
          1. Using the WMI Control Tool
          2. Using the Scriptomatic
          3. Examining the Status of the WMI Service
          4. Using WBEMtest.exe
        3. Testing Remote WMI Service
          1. Remotely Using the WMI Control Tool
        4. Testing Scripting Interface
        5. Obtaining Diagnostic Information
          1. Enabling Verbose WMI Logging
          2. Examining the WMI Log Files
          3. Using the Err Tool
          4. Using MofComp.exe
          5. Using WMIcheck
        6. General WMI Troubleshooting Steps
        7. Working with Logging Step-by-Step Exercises
        8. One Step Further: Compiling MOF files
          1. Chapter 21 Quick Reference
    7. V. Appendices
      1. A. VBScript Documentation
        1. Constants
        2. VBScript Run-Time Errors
        3. VBScript Syntax Errors
        4. FileSystemObject Object Model
      2. B. ADSI Documentation
        1. Computer Object Mapping
        2. Domain Object User Interface Mapping
        3. Group Object User Interface Mapping
        4. Object Property Tab
        5. Organizational Unit User Interface Mapping
        6. Printer Object User Interface Mapping
        7. Shared Folder Object User Interface Mapping
        8. User Object User Interface Mapping
      3. C. WMI Documentation
        1. Win32 Classes
        2. WMI Providers
        3. WMI Scripting API Objects
        4. WMI Log Files
        5. WMI Scripting Object Model
      4. D. Documentation Standards
        1. Header Information Section
        2. Reference Information Section
        3. Worker Information Section
        4. Output Information Section
        5. Sample of Documentation Use
        6. Variable Naming Conventions
      5. E. Special Folder Constants
    8. About the Author
    9. Additional Resources for IT Professionals
      1. Microsoft Windows Server
      2. Microsoft Windows Client
      3. Microsoft SQL Server 2005
      4. Microsoft Exchange Server 2003
      5. Scripting
      6. Related Titles
    10. More Great Resources for IT Professionals
      1. Administrator’s Pocket Consultant
      2. Administrator’s Companion
      3. Resource Kit
      4. Self-Paced Training Kit
    11. Index
    12. About the Author
    13. Copyright

    Product information

    • Title: Microsoft® VBScript Step by Step
    • Author(s): Ed Wilson
    • Release date: November 2006
    • Publisher(s): Microsoft Press
    • ISBN: 9780735622975