VBScript WMI and ADSI Unleashed May 2007.pdf

(5567 KB) Pobierz
671064266 UNPDF
671064266.003.png
Don Jones
WMI , and ADSI
Using VBScript, WMI, and ADSI to
Automate Windows ® Administration
UNLEASHED
800 East 96th Street, Indianapolis, Indiana 46240 USA
VBScript ,
671064266.004.png
 
VBScript, WMI, and ADSI Unleashed
Copyright © 2007 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or trans-
mitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written
permission from the publisher. No patent liability is assumed with respect to the use of the infor-
mation contained herein. Although every precaution has been taken in the preparation of this
book, the publisher and author assume no responsibility for errors or omissions. Nor is any liabil-
ity assumed for damages resulting from the use of the information contained herein.
This material may be distributed only subject to the terms and conditions set forth in the Open
Publication License, v1.0 or later (the latest version is presently available at http://www.opencon-
ISBN-13: 978-0-321-50171-4
ISBN-10: 0-321-50171-3
Library of Congress Cataloging-in-Publication Data:
Jones, Don, 1971-
VBScript, WMI and ADSI unleashed : using VBSscript, WMI, and ADSI to automate Windows
administration / Don Jones. — 1st ed.
p. cm.
ISBN 0-321-50171-3 (pbk. : alk. paper) 1. VBScript (Computer program language) 2. Microsoft
Windows (Computer file) 3. Directory services (Computer network technology) I. Title.
QA76.73.V27J67 2007
005.13’3—dc22
Editor-in-Chief
Karen Gettman
Acquisitions Editor
Joan Murray
Managing Editor
Gina Kanouse
Senior Project Editor
Kristy Hart
Copy Editor
Karen Annett
Indexer
Brad Herriman
Proofreader
Williams Woods
Publishing, LLC
Cover Designer
Gary Adair
2007008741
Composition
Bronkella Publishing
Printed in the United States on America
First Printing May 2007
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appro-
priately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term
in this book should not be regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no
warranty or fitness is implied. The information provided is on an “as is” basis. The author and the
publisher shall have neither liability nor responsibility to any person or entity with respect to any
loss or damages arising from the information contained in this book.
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk
purchases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419
corpsales@pearsontechgroup.com
For sales outside of the U.S., please contact
International Sales
international@pearsoned.com
671064266.005.png
Contents at a Glance
Introduction ................................................................................... 1
Part I Introduction to Windows Administrative Scripting
1 Scripting Concepts and Terminology ................................................. 13
2 Running Scripts ............................................................................. 21
3 The Components of a Script ............................................................ 39
4 Designing a Script .......................................................................... 55
Part II VBScript Tutorial
5 Functions, Objects, Variables, and More ............................................. 75
6 Input and Output ......................................................................... 101
7 Manipulating Numbers ................................................................. 115
8 Manipulating Strings ..................................................................... 129
9 Manipulating Other Types of Data .................................................. 145
10 Controlling the Flow of Execution .................................................. 155
11 Built-In Scripting Objects ............................................................... 173
12 Working with the File System ......................................................... 193
13 Putting It All Together: Creating Your First Script from Scratch ............. 219
Part III Windows Management Instrumentation and Active Directory
Services Interface
14 Working with ADSI Providers ......................................................... 247
15 Manipulating Domains .................................................................. 257
16 Manipulating Users and Groups ...................................................... 271
17 Understanding WMI ..................................................................... 283
18 Querying Basic WMI Information ................................................... 299
19 Querying Complex WMI Information .............................................. 317
20 Putting It All Together: Your First WMI/ADSI Script ............................ 335
21 Testing and Debugging WMI and ADSI Queries ................................. 357
Part IV Advanced Scripting Techniques
22 Modular Script Programming .......................................................... 373
23 Scripts Packaging and Protection ..................................................... 389
671064266.001.png
24 Scripting Security ......................................................................... 399
25 Introduction to HTML Applications ................................................. 409
26 Debugging Tips, Tools, and Techniques ............................................ 421
Part V Ready-to-Run Examples
27 Logon and Logoff Scripts ............................................................... 439
28 Windows and Domain Administration Scripts ................................... 455
29 Network Administration Scripts ...................................................... 481
30 WMI and ADSI Scripts ................................................................... 497
Appendix .................................................................................... 509
Index ......................................................................................... 523
671064266.002.png
Zgłoś jeśli naruszono regulamin