Home > Store

Managing Windows with VBScript and WMI

Register your product to gain access to bonus material or receive a coupon.

Managing Windows with VBScript and WMI


  • Sorry, this book is no longer in print.
Not for Sale



The definitive guide to scripting for all Windows administrators, helping them to simplify their work and make their network more secure.

° Demystifies scripting for administrators, showing how VBScript and WMI can help ease repetitive or complex tasks

° Organized around tasks, and heavily cross-referenced, allowing quick access to information of immediate value

° Based on the author's years of experience teaching and training

° Most other books on scripting focus on developers, not administrators


  • Copyright 2004
  • Edition: 1st
  • Book
  • ISBN-10: 0-321-21334-3
  • ISBN-13: 978-0-321-21334-1

"Finally, a step-by-step VBScripting book to make you look like a programmer without the time and sweat! Don't waste your time searching the Internet for examples--this book does it for you!"

--Greg A. Marino, Senior Systems Engineer/Consultant, Westtown Consulting Group, Inc.

Visual Basic Scripting (VBScript) and Windows Management Instrumentation (WMI) are vital tools for systems administrators grappling with the increasing complexity of Windows technologies. However, busy admins have been without a straightforward guide to scripting...until now.

Managing Windows® with VBScript and WMI explains how Windows administrators can effectively use VBScript to automate common administrative tasks and simplify complex ones. Detailed coverage of security concerns provides admins with the means for safely using VBScript in Windows environments. The book is organized around the problems you face daily, with reusable examples and coverage of Windows NT, Windows 2000, Windows XP, and Windows 2003.

This user-friendly reference demystifies scripting and then shows you how to produce new scripts from scratch. You will be producing useful scripts right away as you study the VBScript language and learn how to control nearly every aspect of the Windows operating system with WMI and the Active Directory Services Interface (ASDI). You will be able to build your own administrative Web pages and use advanced scripting technologies such as script encryption, scripting components, and script security. The book closes with still more ready-made example scripts accompanied by complete line-by-line explanations. The CD includes all the code from the book and trial versions of PrimalScript 3.0 and VbsEdit. A companion Web site provides updates and errata.

Inside you will find answers to such questions as:

  • How do you write effective logon scripts? Chapter 11
  • How do you write scripts that query and modify user and group information? Chapter 16
  • How can you query the IP addresses from multiple network adapters in multiple remote computers? Chapter 19
  • How can you design, write, run, test, and debug your own administrative Web pages? Chapter 24
  • How can you reuse code between various scripts? Chapter 25


Related Article

Using WSH Scripts with the Windows Management Interface

Author's Site

Click for the Author's Web Site related to this title.

Sample Content

Online Sample Chapter

Putting It All Together: Your First WMI/ADSI Script

Downloadable Sample Chapter

Download the Sample Chapter related to this title.

Table of Contents

Preface xxi
Acknowledgments xxxv
About the Author xxxvii


Chapter 1 Scripting Concepts and Terminology 3

What Is Scripting? 3
Script Hosts 4
ActiveX Scripting Languages 6
The Component Object Model (COM) 9
Critical Scripting Security Issues 9
Review 10

Chapter 2 Running Scripts 11

Windows Script Host 11
Command-Line Scripts 13
Notepad and Script Editors 16
Bare Bones: Notepad 16
A Step Up: Programmer's File Editor 17
Script-Specific: VBScript Editors 18
Writing Your First Script 23
Running Your First Script 25
Debugging Your First Script 25
Review 26

Chapter 3 The Components of a Script 29

A Typical VBScript 29
Functions 32
Subroutines 33
Main Script 34
Using Custom Functions and Subroutines 36
Using Intrinsic Functions and Statements 38
Making Decisions in a Script 40
Comments and Documentation 40
Review 45

Chapter 4 Designing a Script 47

Creating a Task List 48
Selecting the Appropriate Tools 50
Displaying a Message 51
Mapping a Drive 53
Checking Group Membership 54
Mapping a Printer 54
Getting the Local IP Address 54
Getting the Third Octet from the IP Address 56
All Tasks Accounted For 56
Creating Modules to Perform Tasks 57
Validating User Input 63
Planning for Errors 63
Creating Script Libraries 66
Review 66


Chapter 5 Functions, Objects, Variables, and More 71

What Are Variables? 72
Declaring Variables 76
Understanding Data Types 78
Assigning Data to Variables 79
Data Coercion 80
What Are Functions? 82
Input Parameters 82
Output Values 84
Intrinsic versus Custom Functions 85
What Are Statements and Subroutines? 89
Functions, without the Output 89
What Are Objects? 92
Properties 92
Methods 93
Collections 93
A Sample Object 94
Scripting with Objects 95
Review 97

Chapter 6 Input and Output 99

Displaying Messages 99
The MsgBox Statement and Function 100
More Complex Messages 104
MsgBox Best Practices 105
Go Generic with WScript.Echo 106
Asking for Input 107
Graphical Input 107
Command-Line Input 109
Command-Line Parameters as Input 110
Running Command-Line Scripts 110
Parsing Parameters 110
Review 114

Chapter 7 Manipulating Numbers 117

Numbers in VBScript 117
Basic Arithmetic 118
Advanced Arithmetic 121
Boolean Math 124
Converting Numeric Data Types 129
Converting Other Data Types to Numeric Data 130
Review 130

Chapter 8 Manipulating Strings 133

Strings in VBScript 133
Working with Substrings 135
Concatenating Strings 139
Changing Strings 141
Formatting Strings 143
Converting Other Data Types to String Data 144
Review 145

Chapter 9 Manipulating Other Types of Data 147

Working with Dates and Times 147
Dates and Times in VBScript 148
Getting the Date or Time 148
Converting Date and Time Data 149
Working with Past and Future Dates 150
Working with Arrays 150
Arrays in VBScript 151
Creating and Manipulating Arrays 152
Working with Array Data 154
Working with Bytes 155
Bytes in VBScript 155
Converting Byte Data 156
Review 156

Chapter 10 Controlling the Flow of Execution 157

Conditional Execution 158
If...Then 158
Select...Case 163
Loops 164
Do While...Loop and Do...Loop While 164
Do Until...Loop and Do...Loop Until 166
For...Next 166
For Each...Next 167
Exiting Loops 169
Putting It All Together 170
Review 173

Chapter 11 Built-in Scripting Objects 175

The WScript Object 175
The Network Object 176
Overview 177
Methods and Properties 177
Practical Application 182
The Shell Object 183
Overview 183
Methods and Properties 183
The Shortcut Object 190
Methods and Properties 190
Practical Application 191
Review 192

Chapter 12 Working with the File System 193

The FileSystemObject Library 193
Working with Drives 194
Working with Drive Objects 195
Working with Folders 197
Working with Folder Objects 198
Folder Attributes 200
Properties That Are Objects 203
Working with Files 204
Working with File Objects 204
Reading and Writing Text Files 207
Other FSO Methods and Properties 211
Creating a Log File Scanner 212
Review 221

Chapter 13 Putting It All Together: Your First Script 223

Designing the Script 224
Gathering Facts 224
Defining Tasks 225
Outlining the Script 226
Writing Functions and Subroutines 227
Identifying Candidate Modules 227
Writing the Filename Formatting Function 227
Writing the Main Script 232
Identifying Potential Errors 237
Testing the Script 240
Analyzing the Results 242
Adding Debug Code 243
Modifying the Script 246
Completing the Script 248
Review 251


Chapter 14 Working with ADSI Providers 255

Using ADSI Objects 255
Using the WinNT Provider 257
Examples 259
Using the LDAP Provider 260
Other Providers 263
Review 263

Chapter 15 Manipulating Domains 265

Querying Domain Information 265
Changing Domain Settings 267
Working with OUs 268
Creating an OU 268
Modifying an OU 270
Querying an OU 272
Deleting an OU 272
Putting It All Together 273
Review 279

Chapter 16 Manipulating Users and Groups 281

Creating Users and Groups 281
The WinNT Way 282
The LDAP Way 283
Querying User Information 284
Changing User Settings 285
Working with Groups 286
Putting It All Together 288
Review 292

Chapter 17 Understanding WMI 293

The WMI Hierarchy 293
Providers and Consumers 295
WMI Versions 296
Exploring WMI's Capabilities 296
WQL Queries 300
Installing WMI 301
Using the WMI Tools 302
Scriptomatic 304
Really--It's This Easy 304
Find the Class 304
Write the Query, Test the Query 306
Write the Script 307
Try the Script 309
Review 309

Chapter 18 Querying Basic WMI Information 311

The WMI Query Language (WQL) 311
The Basics 313
Boolean Operators 314
Comparison Operators 314
Associators, References, and Keys 316
Determining What to Query 316
Testing the Query 319
Writing the Query in VBScript 321
Using the Query Results 326
Alternative Methods 328
Review 329

Chapter 19 Querying Complex WMI Information 331

Understanding WMI Relationships 331
Associating WMI Instances 336
Writing the Query 340
Testing the Query 341
Writing the Query in VBScript 341
Another Example 345
Review 349

Chapter 20 Putting It All Together: Your First WMI/ADSI Script 351

Designing the Script 351
Writing Functions and Subroutines 357
Writing the Main Script 360
Testing the Script 369
Review 374


Chapter 21 Active Server Pages Crash Course 377

About ASP 378
VBScript in ASP 379
The Response Object 381
Writing Output 382
Saving Cookies 382
Ending 384
The Request Object 384
HTML Forms 384
Cookies 385
A Sample ASP Script 385
Testing ASP Scripts 389
Review 391

Chapter 22 Adding Administrative Script to a Web Page 393

The Basic Web Page 393
Adding Functions and Subroutines 396
Adding Inline Script 397
The Result 403
Review 417

Chapter 23 Web Page Security Overview 419

The ASP Security Context 419
Prohibited Behaviors 423
IIS 4.0, 5.0, and 5.1 versus IIS 6.0 424
NTFS and IIS Security 427
Writing Secure ASP Code 427
Review 431

Chapter 24 Putting It All Together: Your First Administrative Web Pages 433

Checking User Account Status 433
Designing the Page 434
Writing Functions and Subroutines 435
Writing the Main Script 437
Testing the Page 442
Administering IIS 443
Designing the Page 443
Writing Functions and Subroutines 444
Writing the Main Script 449
Review 460


Chapter 25 Modular Script Programming 463

Introduction to Windows Script Components 463
Scripting and XML 465
Review 474

Chapter 26 Using Script Components 475

Obtaining the Component 475
Reviewing the Component 476
Using the Component 477
Review 479

Chapter 27 Encoded Scripts 481

Installing the Script Encoder 482
Writing Encoded Scripts 482
Running Encoded Scripts 485
Review 486

Chapter 28 Scripting Security 487

Why Scripting Can Be Dangerous 487
Security Improvements in Windows XP and Windows Server 2003 488
Digitally Signing Scripts 490
Running Only Signed Scripts 493
Ways to Implement Safe Scripting 494
The Filename Extension Game 494
Script Signing 494
Antivirus Software 494
Defunct Techniques 495
Review 495


Chapter 29 Logon and Logoff Scripts 499

NT and Active Directory Logon Scripts 500
Active Directory-Specific Logon Scripts 507
Active Directory Logoff Scripts 513
Review 516

Chapter 30 Windows and Domain Administration Scripts 517

Automating User Creation 517
Finding Inactive Users 527
Collecting System Information 533
Review 539

Chapter 31 Network Administration Scripts 541

Shutting Down Remote Computers 541
Listing Remote Shares 544
Finding Out Who Has a File Open 547
Uninstall Remote MSI Packages 549
Adding Users from Excel 553
Listing Hot Fixes and Software 562
Review 566

Chapter 32 WMI and ADSI Scripts 567

The All-Purpose WMI Query Script 567
The All-Purpose WMI Update Script 569
The All-Purpose ADSI Object Creation Script 571
The All-Purpose ADSI Object Query Script 572
The All-Purpose ADSI Object Deletion Script 573
Mass Password Changes with ADSI 574
Review 576


Appendix Administrator's Quick Script Reference 579

Index 591


Download the Index file related to this title.


Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership