82

How to access - · PDF file8 Using WMI ... E Special Folder Constants ... Creating a Useful Error Message

Embed Size (px)

Citation preview

  • http://www.facebook.com/share.php?u=http://www.microsoftpressstore.com/title/9780735622975http://twitter.com/?status=RT: download a free sample chapter http://www.microsoftpressstore.com/title/9780735622975https://plusone.google.com/share?url=http://www.microsoftpressstore.com/title/9780735622975http://www.linkedin.com/shareArticle?mini=true&url=http://www.microsoftpressstore.com/title/9780735622975http://www.stumbleupon.com/submit?url=http://www.microsoftpressstore.com/title/9780735622975/Free-Sample-Chapter

  • How to access your CD files

    Microsoft Press

    The print edition of this book includes a CD. To access the CD files, go to http://aka.ms/VBSScriptSBS/files, and look for the Downloads tab. Note: Use a desktop web browser, as files may not be accessible from all ereader devices. Questions? Please contact: [email protected]

  • PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399

    Copyright 2007 by Ed Wilson

    All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.

    Library of Congress Control Number: 2006934395

    Printed and bound in the United States of America.

    1 2 3 4 5 6 7 8 9 QWT 1 0 9 8 7 6

    Distributed in Canada by H.B. Fenn and Company Ltd.

    A CIP catalogue record for this book is available from the British Library.

    Microsoft Press books are available through booksellers and distributors worldwide. For further infor-mation about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to [email protected].

    Microsoft, Microsoft Press, Active Directory, ActiveX, Excel, MSDN, Visual Basic, Win32, Windows, Windows NT, Windows Server, and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

    Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred.

    This book expresses the authors views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.

    Acquisitions Editor: Martin DelRe Project Editor: Maureen Williams Zimmerman Copy Editor: Sarah Wales-McGrath Technical Reviewer: David Holder Indexer: Jeanne Busemeyer

    Body Part No. X13-24158

    http:[email protected]

  • Dedication

    This book is dedicated to my best friend, Teresa.

  • Con

    Part I

    1

    2

    3

    4

    5

    Part II

    6

    7

    8

    9

    10

    Part III

    11

    12

    13

    14

    15

    16

    17

    18

    tents at a Glance

    Covering the Basics

    Starting from Scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Looping Through the Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    Adding Intelligence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

    Working with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

    More Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

    Basic Windows Administration

    Working with the File System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

    Working with Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

    Using WMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

    WMI Continued . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

    Querying WMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

    Advanced Windows Administration

    Introduction to Active Directory Service Interfaces . . . . . . . . . . . . . . . 251

    Writing for ADSI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

    Using ADO to Perform Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

    Configuring Network Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315

    Using Subroutines and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329

    v

    Logon Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349

    Working with the Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367

    Working with Printers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

  • vi

    Part IV

    19

    20

    21

    Part V

    A

    B

    C

    D

    E

    Contents at a Glance

    Scripting Other Applications

    Managing IIS 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395

    Working with Exchange 2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407

    Troubleshooting WMI Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419

    Appendices

    VBScript Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

    ADSI Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449

    WMI Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

    Documentation Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463

    Special Folder Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467

    Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469

  • Tab

    Part I

    1

    2

    What

    le of Contents

    Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

    Covering the Basics

    Starting from Scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Running Your First Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Reference Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    Output Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    Enhancing Your Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    Modifying an Existing Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    Modifying the Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    Modifying the Reference Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    Modifying the Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    Modifying the Output Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    Exploring a Script: Step-by-Step Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    One Step Further: Customizing an Existing Script. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    Looping Through the Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    Adding Power to Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    For EachNext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

    Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

    Reference Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

    Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

    ForNext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    Reference Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .