Training
Certifications
Books
Special Offers
Community




 
Microsoft® Windows® 2000 Scripting Guide
Author The Microsoft Windows Resource Kit Scripting Team
Pages 1328
Disk 1 Companion CD(s)
Level Int/Adv
Published 12/16/2002
ISBN 9780735618671
Price $49.99
To see this book's discounted price, select a reseller below.
 

More Information

About the Book
Table of Contents
Sample Chapter
Index
Related Series
Related Books
About the Author

Support: Book & CD

Rate this book
Barnes Noble Amazon Quantum Books

 

Table of Contents


Introductionxxvii
PART I: SCRIPTING CONCEPTS AND TECHNOLOGIES FOR SYSTEM ADMINISTRATION1
CHAPTER 1 Introduction to Windows Script Technologies 3
CHAPTER 2 VBScript Primer 15
    VBScript Overview 17
        Working with Objects 18
            Connecting to Objects 19
            Creating an Object Reference 20
            Calling Methods 21
            Retrieving Properties 22
        Variables 23
        Constants 25
        Strings 26
            Strings as Variables 27
            Concatenating Strings 29
        Collections 30
            For Each 31
            Collections with Zero Items 33
        Looping 34
            For Next 34
        Making Decisions 37
            Taking Multiple Actions by Using If Then Else 38
        Arrays 39
        Input 41
        Error Handling 43
            Using the Err Object 43
            Clearing Errors 46
    VBScript Reference 47
        Working with Variables 49
            Initializing Variables 51
        Using Constants 53
            Defining Constants 54
            Using Intrinsic Constants 54
        VBScript Data Types 56
        Working with Dates and Times 59
            Retrieving Current Date and Time Values 60
            Verifying That a Value Is a Date 61
            Retrieving Specific Portions of a Date and Time Value 62
            Date Arithmetic 68
            Formatting Date and Time Values 70
        Working with Strings 73
            Manipulating Strings and String Lengths 74
            Searching for Text in a String 79
            Modifying String Case 81
        Working with Numbers 82
            Arithmetic Precedence 82
            Formatting Numbers 84
            Formatting Percentages 86
        Running Statements Multiple Times 87
            Do Loop 88
            Checking the Loop Condition 89
            Exiting a Loop 90
        Making Decisions 92
            Testing Multiple Conditions 92
            If Then ElseIf 93
            Select Case 96
        Arrays 97
            Creating Arrays 98
            Creating Dynamic Arrays 100
            Converting a Delimited String to an Array 101
            Alternatives to Using Arrays 103
        Error Handling 104
            Handling Run-Time Errors 106
            Toggling Error Handling 108
            Handling Errors in COM Objects 110
        Procedures 111
            Calling a Procedure 112
            Functions 114
            Recursion 120
        COM Objects 121
            The COM Process 122
            Binding 124
            Choosing a Method for Binding to an Automation Object 124
            Verifying Object References 126
            Unloading Objects from Memory 127
CHAPTER 3 WSH Primer 129
    WSH Overview 130
    WSH Architecture 134
            Components of the WSH Environment 135
            How the Components of the WSH Environment Work Together 139
            WSH Object Model 140
    Running WSH Scripts 140
        Running Scripts from the Command Line 142
        Scheduling the Running of Scripts 146
        Other Methods of Running Scripts 146
    WSH Objects 147
        WScript Object 148
            Using COM Objects 150
            Handling Input and Output 154
            Working with Command-Line Arguments 162
            Controlling How a Script Runs 176
            Obtaining WSH Environment Information 179
            Handling Events 181
        WshShell Object 181
            Running Programs 183
            Working with Shortcuts 191
            Working with Special Folders 195
            Environment Variables 197
            Logging an Event 201
            Reading From and Writing to the Local Registry 203
            Sending Keystrokes to a Program 206
            Retrieving and Changing a Script's Current Working Directory 211
            Displaying Timed Message Boxes 212
        WshNetwork Object 219
            Managing Network Drives 221
            Managing Network Printers 224
            Obtaining User and Computer Information 226
        WshController Object 227
            Running Scripts on Remote Computers 230
            Monitoring Status of Remotely Running Scripts 231
            Examining Errors Produced by Remotely Running Scripts 232
            Limitations of Remote WSH 234
    Securing Scripts 234
        Digitally Signing Scripts 235
            Enforcing the Use of Signed Scripts 236
            Programmatically Signing a Script 237
            Programmatically Verifying a Signed Script 237
        Restricting the Ability to Run Scripts 238
            Disabling Windows Script Host 239
CHAPTER 4 Script Runtime Primer 241
    Script Runtime Overview 242
    FileSystemObject 243
        Managing Disk Drives 243
            Returning a Collection of Disk Drives 244
            Binding to a Specific Disk Drive 245
            Enumerating Disk Drive Properties 245
            Ensuring That a Drive is Ready 248
        Managing Folders 249
            Binding to a Folder 249
            Verifying That a Folder Exists 250
            Creating a Folder 250
            Deleting a Folder 251
            Copying a Folder and Its Contents 252
            Moving a Folder and Its Contents 254
            Renaming a Folder 255
        Using Folder Properties 256
            Enumerating Folder Properties 257
        Managing Folder Attributes 258
            Changing Folder Attributes 261
            Enumerating the Files in a Folder 262
            Enumerating Subfolders 263
        Managing Files 266
            Binding to a File 266
            Verifying That a File Exists 267
            Deleting a File 268
            Copying a File 270
            Moving a File 272
            Renaming a File 272
        Retrieving File Properties 273
            Enumerating File Attributes 275
            Configuring File Attributes 276
            Parsing File Paths 277
            Retrieving the File Version 279
        Reading and Writing Text Files 280
            Reading Text Files 285
            Writing to Text Files 292
    Dictionary Object 296
        Creating a Dictionary 296
            Configuring Dictionary Properties 297
            Adding Key-Item Pairs to a Dictionary 298
        Manipulating Keys and Items in a Dictionary 299
            Determining the Number of Key-Item Pairs in a Dictionary 299
            Enumerating Keys and Items in a Dictionary 300
            Verifying the Existence of a Specific Key 301
            Modifying an Item in a Dictionary 302
            Removing Key-Item Pairs from a Dictionary 303
CHAPTER 5 ADSI Scripting Primer 307
    ADSI Overview 308
    ADSI Scripting Fundamentals 309
        Primary ADSI Scripting Tasks 310
            Creating Directory Service Objects 310
            Modifying Directory Service Objects 313
            Reading Attributes of Directory Service Objects 315
            Deleting Directory Service Objects 317
        Comparing the Primary Scripting Tasks 319
        Building ADSI Scripts 320
            Step 1: Establishing a Connection 320
            Step 2: Performing a Task 326
            Step 3: Committing to Active Directory 331
        Performing Multiple Scripting Tasks 332
    Advanced ADSI Scripting Operations 336
        Administering Multivalued Attributes 336
            Modifying Multivalued Attributes 336
            Reading Multivalued Attributes 344
        Data Caching 346
            Making Explicit Calls by Using the GetInfo Method 347
            Making Explicit Calls by Using the GetInfoEx Method 348
        Copying, Moving, and Renaming Objects 350
            Copying Objects 350
            Moving and Renaming Objects 354
        Searching 358
            Searching Active Directory 359
            Optimizing Search Performance 378
            Performing an Administrative Task Using a Result Set 382
        Enumerating Active Directory Objects in Containers 386
            Scripting Container Enumeration 386
        Root Directory Service Entry 390
            Scripting with rootDSE 391
    Active Directory Architecture 393
        Physical Architecture 393
        Logical Structure 394
            Classes and Attributes 395
            Active Directory Replication and Indexing 406
            Operational Attributes 412
    ADSI Architecture 414
        ADSI Layers 416
        ADSI Interfaces 421
CHAPTER 6 WMI Scripting Primer 429
    WMI Overview 431
    WMI Architecture 436
        Managed Resources 438
        WMI Infrastructure 439
        WMI Consumers 445
        WMI Security 445
            WMI Namespace-Level Security 446
            DCOM Security 447
            Standard Windows Operating System Security 448
    Common Information Model 448
        Blueprint for Management 451
            Namespaces 452
            Class Categories 460
            CIM Class Types 465
            Components of a Class 468
        Exploring the CIM Repository 481
    WMI Scripting Library 482
        WMI Scripting Library Object Model 482
            SWbemLocator 486
            SWbemServices 488
    Writing WMI Scripts 494
        Connecting to WMI Using the WMI Moniker 495
            The "WinMgmts:" Prefix 496
            WMI Security Settings 497
            Using WMI Object Paths 503
        Retrieving Managed Resources Using WMI Query Language 505
            Returning All Properties of All Instances of a Class 507
            Returning Selected Properties of All Instances of a Class 508
            Returning All Properties of Selected Instances of a Class 509
            Creating Targeted Queries Using AND or OR 514
            Returning Selected Properties of Selected Instances of a Class 514
            Creating Faster Queries by Using a Forward-only Enumerator 515
        Working with Dates and Times 517
            Converting WMI Dates to a Standard Date-Time Format 519
            Converting a Standard Date to a WMI Date-Time Format 521
        Creating Scripts Based on WMI Templates 525
            Retrieving and Displaying Properties of a Managed Resource 525
            Retrieving and Displaying All Properties of a Managed Resource 526
            Writing Resource Properties 527
            Calling Methods 529
            Creating Resources 530
            Deleting Resources 531
        Monitoring Resources by Using WMI Event Notifications 532
            Three Steps in a WMI Monitoring Script 535
            How WMI Event Notification Works 538
            Enhanced WMI Monitoring Scripts 541
PART II: SCRIPTING SOLUTIONS FOR SYSTEM ADMINISTRATION 547
CHAPTER 7 Active Directory Users 549
    User Account Overview 551
    Active Directory User Accounts 552
        Active Directory User Account Objects 552
            User Account Types 552
            Identification Attributes 553
    Creating User Accounts 555
        Configuring User Account Passwords 558
            Setting User Account Passwords 559
            Changing User Account Passwords 560
        Reading User Account Password Attributes 561
            Displaying Password Attributes Accessible from userAccountControl 563
            Determining When a Password Was Last Set 564
        Configuring User Account Password Attributes 565
            Changing Flags in the userAccountControl Attribute 565
            Configuring a Password Change at Next Logon Requirement 566
    Managing User Accounts 567
            Enabling or Disabling a User Account 568
            Determining Whether an Account Is Enabled or Disabled 569
        Reading and Writing User Account Attributes 570
            Reading Attributes 573
            Writing Values to the Attributes 576
            Modifying a Multivalued Attribute 577
            Clearing Attributes 580
        Copying, Moving, and Renaming User Accounts 581
            Copying User Accounts 581
            Moving and Renaming User Accounts 584
    Deleting User Accounts 588
    Searching Active Directory for User Accounts 589
        Searching for an Attribute in a Container 593
        Limiting a Search for an Attribute in a Container to User Account Types 596
        Searching for a User Account Attribute in a Container and Its Subcontainers 598
        Verifying That an Attribute Is Unique in the Forest 600
        Searching for Empty Attribute Values 601
        Using Wildcards in Search Filters 606
        Searching for Multivalued Attributes 608
        Sorting the Result Set 610
        Modifying Multiple User Accounts by Using the Result Set from a Search 611
    Managing User Accounts by Enumeration 613
            Limiting Enumeration with Filters and Hints 614
CHAPTER 8 Computer Assets 617
    Computer Assets Overview 618
        Retrieving System Information 619
        Retrieving BIOS Information 623
            Retrieving Information About the BIOS 623
            Retrieving Identifying Information by Using the SMBIOS 628
        Inventorying Computer Hardware 629
            Taking Inventory of Computer Hardware 632
            Identifying the Chassis Type of a Computer 634
    Managing Operating Systems 637
        Identifying the Name and Version Number of the Operating System 637
        Retrieving the Properties of the Operating System 639
        Identifying the Latest Installed Service Pack 643
        Enumerating Installed Hot Fixes 645
    Managing WMI Settings 646
            Enumerating WMI Settings 649
            Configuring WMI Settings 651
    Managing Software 653
        Enumerating Software 654
            Enumerating Installed Software 655
            Enumerating Installed Software Features 658
        Installing, Upgrading, and Removing Software 659
            Installing Software on the Local Computer 660
            Installing Software on a Remote Computer 662
            Upgrading Software 664
            Removing Software 666
    Managing Computer States 667
        Managing Computer Startups 667
            Enumerating Computer Startup Options 668
            Configuring Computer Startup Options 670
            Enumerating Computer Startup Commands 673
        Managing Computer Recovery Options 675
            Enumerating Computer Recovery Options 677
            Configuring Computer Recovery Options 679
            Querying the Event Log for Stop Events 680
        Shutting Down Computers and Logging Off Users 682
            Shutting Down a Computer 684
            Restarting a Computer 685
        Monitoring Changes in Computer Power Status 686
CHAPTER 9 Computer Roles 689
    Computer Roles Overview 690
    Managing Computer Accounts 690
        Retrieving Basic Logon and Computer Information 693
        Creating Computer Accounts 694
        Deleting Computer Accounts 698
        Deleting Specified Computer Accounts 699
        Modifying Computer Accounts 701
            Enumerating Computer Account Attributes 701
            Configuring the Computer Account Location Attribute 703
            Renaming Computer Accounts 704
            Moving Computer Accounts 705
            Resetting Computer Account Passwords 706
        Searching for Computer Accounts in Active Directory 707
            Enumerating All the Computer Accounts in Active Directory 709
            Locating Computer Accounts Based on Their Attributes 710
    Managing Computer Roles 712
        Identifying Computer Roles 713
        Identifying the Role of a Computer Based on the Service It Provides 715
        Identifying Active Directory-Specific Roles 716
            Enumerating Domain Controllers 716
            Identifying the Current Domain Controller for a Computer 718
            Identifying Operations Master Roles 719
            Identifying Global Catalog Servers 722
            Enabling or Disabling Global Catalog Servers 723
CHAPTER 10 Disks and File Systems 725
    Disks and File Systems Overview 726
    Managing and Monitoring Disk Drives 726
        Managing Disk Partitions 730
        Managing Logical Disk Drives 733
            Identifying Drives and Drive Types 735
            Changing Logical Disk Volume Names 737
        Managing Disk Space 738
            Enumerating Disk Space on a Computer 738
            Enumerating Disk Space by User 739
            Monitoring Free Disk Space in Real-Time 740
    Managing Disk Quotas 742
        Managing Disk Quotas on the NTFS File System 742
            Enumerating Disk Quota Settings 744
            Enabling and Disabling Disk Quotas 745
            Configuring Default Disk Quota Settings 746
        Managing Disk Quotas for Individual Users 748
            Enumerating Disk Quotas 748
            Adding a New Disk Quota Entry 750
            Modifying a Disk Quota Entry 752
            Deleting a Disk Quota Entry 752
    Managing File Systems 754
            Identifying the File System Type 754
            Enumerating NTFS Properties 755
            Modifying NTFS Properties 760
        Managing Page Files 762
            Monitoring Page File Use 764
            Configuring Page File Properties 765
CHAPTER 11 Files and Folders 767
    Files and Folders Overview 768
        Managing Files and Folders Using WMI 768
            Comparing WMI and the FileSystemObject 769
        Managing Files and Folders Using the Windows Shell Object 773
    Folders and Folder Objects 775
        Enumerating Folders and Folder Properties 778
            Enumerating All the Folders on a Computer 780
            Enumerating the Subfolders of a Folder 781
            Enumerating a Specific Set of Folders 783
            Enumerating Folders by Date 784
            Enumerating Special Folders 787
            Enumerating the Items in a Special Folder 790
            Binding to a Folder by Using the Browse For Folder Dialog Box 791
        Managing Folders 794
            Renaming Folders 794
            Moving Folders by Using the Rename Method 795
            Copying Folders by Using WMI 796
            Copying Folders by Using the Shell Folder Object 797
            Moving Folders by Using the Shell Folder Object 800
            Deleting Folders 801
            Compressing and Uncompressing Folders 802
    Files and File Objects 804
        Enumerating Files and File Properties 804
            Retrieving Extended File Properties 806
            Enumerating All the Files on a Computer 809
            Using an Asynchronous Query to Enumerate All the Files on a Computer 810
            Enumerating All the Files in a Folder 811
            Enumerating a Specific Set of Files 812
        Managing Files 813
            Renaming Files 813
            Changing File Name Extensions 814
            Copying Files 816
            Deleting Files 817
            Performing Actions on Files 818
            Identifying Shell Object Verbs 820
    Monitoring the File System 821
            Monitoring File Creation 821
            Monitoring File Deletion 822
            Monitoring File Modification 824
    Managing Shared Folders 825
            Enumerating Shared Folders 826
            Creating Shared Folders 828
            Mapping Shared Folders to Local Folders 830
            Deleting Shared Folders 832
            Modifying Shared Folder Properties 833
        Publishing Shared Folders in Active Directory 834
        Managing Published Folders 836
            Enumerating Published Folders 836
            Searching for Published Folders in Active Directory 838
            Deleting a Published Folder in Active Directory 839
CHAPTER 12 Logs 841
    Logs Overview 842
    Managing Logs 842
        Managing Event Logs 844
            Retrieving Event Log Properties 845
            Configuring Event Log Properties 850
            Backing Up and Clearing Event Logs 852
            Creating Unique File Names When Backing Up Event Logs 856
        Querying Event Logs 857
            Querying a Specific Event Log 861
            Querying an Event Log for a Subset of Events 862
            Retrieving Event Log Records from a Specified Day 863
            Asynchronously Retrieving Event Log Statistics 865
            Copying Events to a Database 867
        Writing Events to Event Logs 870
            Writing to Event Logs 871
            Creating Detailed Event Log Entry Descriptions 872
            Creating Custom Event Logs 874
        Managing Plain-Text Logs 876
            Parsing Comma-Separated-Values Logs 877
            Parsing Fixed-Width Logs 879
CHAPTER 13 Printing 881
    Printing Overview 882
    Monitoring Printers, Print Queues, and Print Jobs 885
        Monitoring Printers 885
            Monitoring Printer Status 887
            Monitoring Printer Status in Real Time 888
            Filtering Printer Status Displays 892
            Monitoring Printer Status by Using a Temporary Event Subscription 893
            Verifying the Status of the Print Service 896
        Monitoring Printer Workloads 897
            Reporting Print Queue Statistics 897
        Monitoring Print Jobs 899
            Monitoring Print Job Status 903
            Monitoring the Time Print Jobs Spend in a Print Queue 905
    Managing Printer Operations, Print Queues, and Print Jobs 906
        Managing Printer Operations 906
            Enumerating Printers and Print Capabilities 910
            Pausing Printers 912
            Resuming Printers 913
        Managing Print Queues 913
            Purging Print Queues 914
        Managing Print Jobs 914
            Pausing Print Jobs 915
            Resuming Print Jobs 916
    Configuring Printers and Print Jobs 917
        Configuring Printer Properties 917
        Configuring Printer Availability 918
        Tracking Printer Locations 919
            Enabling Printer Location Tracking 920
            Configuring Printer Locations 921
        Configuring Print Jobs 923
            Configuring Print Job Properties 924
    Managing Printer Connections on Client Computers 926
        Enumerating Printer Connections 927
        Adding and Deleting Printer Connections 928
            Adding a Printer Connection by Using WSH 929
            Removing a Printer Connection 930
    Searching for Printers in Active Directory 930
        Enumerating All the Published Printers in a Domain 931
        Searching for Specific Printers in a Domain 932
CHAPTER 14 Processes 937
    Processes Overview 938
    Managing Processes 939
        Monitoring Processes 941
            Monitoring Processes for Availability 942
            Monitoring Processes for Reliability 943
            Monitoring Processes for Performance 945
            Displaying Current Process Performance Data 950
        Enumerating Additional Process Properties 954
            Determining Process Owners 955
            Monitoring Threads 956
        Creating and Terminating Processes 959
            Creating Processes 959
            Modifying Process Startup Options 961
            Terminating Processes 965
CHAPTER 15 Services 969
    Services Overview 971
    Monitoring Services 973
        Monitoring Service Availability 974
        Monitoring Service Reliability 976
    Retrieving Service Properties 978
        Enumerating Service Properties 980
        Identifying the Services Running in a Process 983
    Changing Service State 987
        Determining Which Services Can Be Stopped or Paused 989
        Stopping or Pausing Services 990
        Starting or Resuming Services 991
    Enumerating Dependent and Antecedent Services 993
        Enumerating Dependent Services 994
        Enumerating Antecedent Services 997
        Stopping and Starting Dependent Services 998
    Configuring Services 1001
        Configuring Service Start Options 1003
        Configuring Error Control Codes for Autostart Services 1004
    Managing Service Accounts and Service Account Passwords 1006
        Configuring Service Accounts 1007
        Configuring Service Account Passwords 1009
    Installing and Removing Services 1010
        Installing Services 1011
        Removing Services 1013
CHAPTER 16 Registry 1015
    Registry Overview 1016
    Managing the Registry 1024
        Backing Up the Registry 1025
        Reading Entry Values and Types 1026
            Reading String-valued and DWORD-valued Entries 1027
            Reading a Multistring-valued Entry 1029
            Reading an Expanded String-valued Entry 1030
            Reading a Binary-valued Entry 1031
        Changing String-valued and DWORD-valued Entries 1033
        Creating Registry Subkeys and Entries 1035
            Creating a Subkey 1035
            Creating String-valued and DWORD-valued Entries 1036
            Creating Multistring-valued Entries 1038
            Creating Expanded String-valued Entries 1040
        Enumerating Keys, Subkeys, and Entries 1041
            Enumerating Subkeys of a Key or Subkey 1042
            Enumerating Entry Names, Values, and Data Types 1043
        Deleting Subkeys and Entries 1045
            Deleting Registry Entries 1045
            Deleting a Registry Subkey 1046
        Checking Registry Subkey Access Rights 1047
    Monitoring the Registry 1050
            Monitoring Subtree-Level Events 1050
            Monitoring Subkey-Level Events 1052
            Monitoring Entry-Level Events 1053
PART III: SCRIPTING FOR THE ENTERPRISE 1055
CHAPTER 17 Creating Enterprise Scripts 1057
    Enterprise Scripts Overview 1059
    Retrieving Arguments 1060
        Retrieving Arguments from a Text File 1061
            Using a Text File as a Command-Line Argument 1064
        Retrieving Arguments from a Database 1067
        Retrieving Arguments from an Active Directory Container 1070
    Displaying Output 1072
        Displaying Tabular Script Output in a Command Window 1073
        Displaying Data by Using Internet Explorer 1077
            Displaying Data in a Web Page 1081
            Stopping a Script When Internet Explorer Is Closed 1085
        Working with HTML Applications 1087
        Displaying Script Output by Using the Tabular Data Control 1092
            Sorting Data by Using the Tabular Data Control 1095
            Filtering Data by Using the Tabular Data Control 1099
            Sorting Data by Using a Disconnected Recordset 1101
    Working with Databases 1103
        Connecting to a Database 1105
        Adding New Records to a Database 1107
        Finding Records in a Recordset 1109
        Updating Records in a Database 1112
        Deleting Selected Records from a Database 1114
        Deleting All Records in a Database Table 1116
    Masking Passwords 1117
        Masking Passwords by Using Internet Explorer 1118
    Sending E-Mail 1120
        Sending E-Mail from a Script 1122
        Sending E-Mail Without Installing the SMTP Service 1123
    Tracking Script Progress 1125
        Tracking Script Progress by Using Internet Explorer 1126
        Tracking Dynamic Script Progress by Using Internet Explorer 1128
        Tracking Script Progress in a Command Window 1133
    Managing Scheduled Tasks 1135
        Enumerating Scheduled Tasks 1137
        Creating Scheduled Tasks 1140
        Deleting Scheduled Tasks 1144
CHAPTER 18 Scripting Guidelines 1147
    Overview of Scripting Guidelines 1148
    Using Naming Conventions 1148
            Naming Scripts 1149
            Naming Variables 1151
            Naming Constants 1156
            Naming Functions and Procedures 1156
    Constructing Scripts 1157
            Choosing a Script Construction 1158
            Creating a Script Template 1160
            Using Functions and Procedures 1161
    Formatting Code 1164
            Using White Space 1164
            Setting Statement Breaks 1168
            Creating Scripts That Are Easier to Read 1170
        Commenting Scripts 1175
            Adding Comments to a Script 1178
            Formatting Comments 1179
            Creating Script Headers 1179
            Creating Function and Procedure Headers 1180
            Creating Script Documentation by Using Comments 1181
            Using Comments as a Debugging Aid 1182
    Debugging and Troubleshooting Scripts 1184
            Adding a Trace Routine to a Script 1184
            Incrementally Running a Script 1186
            Turning Off Error Handling as a Debugging Tool 1187
    Testing Scripts 1188
INDEX1191



Last Updated: December 11, 2002
Top of Page