microsoft windows scripting self-paced learning guide

386 517 0
microsoft windows scripting self-paced learning guide

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

A01T619816.fm Page 1 Tuesday, March 9, 2004 2:11 PM www.it-ebooks.info PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2004 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 Cataloging-in-Publication Data pending. ISBN 0-7356-1981-6 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWT 9 8 7 6 5 4 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 information 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/learning/. Send comments to mspinput@microsoft.com. Microsoft, Microsoft Press, and Outlook are either registered trademarks or trademarks of Microsoft Corpora- tion 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 author’s 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: Valerie Woolley Technical Editor: Alex K. Angelopoulos Indexer: Julie Bess Body Part No. X10-46139 www.it-ebooks.info This book is dedicated to Bobby R. Wilson— teacher, friend, and dad. www.it-ebooks.info www.it-ebooks.info Contents v Contents Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xix A Practical Approach to Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Is This Book for Me? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xx Outline of This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xx Part 1: Covering the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Part 2: Basic Windows Administration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Part 3: Advanced Windows Administration. . . . . . . . . . . . . . . . . . . . . . . . . . xxi Part 4: Scripting Other Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Part 5: Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii About the Companion CD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv Part 1 Covering the Basics 1 Starting from Scratch 3 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Running Your First Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Output Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Enhancing Your Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Docs That Make House Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Modifying an Existing Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Modifying the Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Modifying the Reference Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Modifying the Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Modifying the Output information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Lab 1 Exploring a VBScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Lab 2 Customizing an Existing Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 v www.it-ebooks.info vi Contents 2 Getting in the Loop 25 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Adding Power to Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 For Each…Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 For Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Do While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Do Until Loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Lab 3 Using the For Each…Next Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Lab 4 Modifying the Ping Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 3 Adding Intelligence 45 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 If Then . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Intrinsic Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 If Then ElseIf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 If Then Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Select Case. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 www.it-ebooks.info Contents vii Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Lab 5 Modifying CPUType.vbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Lab 6 Modifying ComputerRoles.vbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4The Power of Many 65 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Command-Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Making the Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Running from the Command Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 No Arguments? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Creating a Useful Error Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Using Multiple Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Tell Me Your Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Reasons for Named Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Making the Change to Named Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Running a Script with Named Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Working with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Moving Past Lame Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 What Does UBound Mean? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Mechanics of Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Lab 7 Working with Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Lab 8 Building Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 www.it-ebooks.info viii Contents Lab 9 Modifying a Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 5 The Power of Many More 93 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Strings and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Parsing Passed Text into an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Output Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Parsing Passed Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Output Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Working with Dictionaries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Using the Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Adding Items to the Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Own Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Lab 10a Implementing Basics for the InStr Command . . . . . . . . . . . . . . . . . . . 106 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Lab 10b Understanding Advanced Features of the InStr Command . . . . . . . . . . 107 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Lab 11 Creating a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Part 2 Basic Windows Administration 6 Working with the File System 113 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Creating File System Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 File It Under Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 File Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 File Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Implementing the Attributes Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Setting File Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 www.it-ebooks.info Contents ix A File, a File, I Need to Create a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Writing to a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 How Shall I Write Thee? Let Me Count the Ways…. . . . . . . . . . . . . . . . . . . 121 Overwriting a File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Existential File Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Lab 12 Creating Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Lab 13 Creating a Log File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 7 Fun with Folders 129 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Working with Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Creating the Basic Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Worker Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Output Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Automatic Cleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Deleting a Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Deleting Multiple Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Binding to Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Does the Folder Exist?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Copying Folders. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Moving On Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Lab 14 Creating Folders. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Lab 15 Deleting Folders. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 8 Why Windows Management Instrumentation? 143 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 What Is WMI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 An Object in Any Other Namespace… . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 More Than Just a Name. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Adding a Touch of Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Querying WMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Header Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 www.it-ebooks.info x Contents Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Lab 16 Retrieving Hotfix Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Lab 17 Echoing the Time Zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 9 WMI Continued 157 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Alternate Ways of Configuring the WMI Moniker . . . . . . . . . . . . . . . . . . . . . . . . 157 Accepting Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Moniker Security Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 WbemPrivilege Has Its Privileges. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Quiz Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 On Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Lab 18a Using the Default WMI Moniker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Lab 18b Invoking the WMI Moniker to Display the Machine Boot Configuration. . 166 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Lab 18c Including Additional Security Permissions. . . . . . . . . . . . . . . . . . . . . . 167 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Lab 19 Using Win32_Environment and VBScript to Learn About WMI . . . . . . . . . 169 Lab Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 10 Using WMI Queries 171 Before You Begin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Tell Me Everything About Everything! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Header information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Reference Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Worker and Output Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Selective Data from All Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Selecting Multiple Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Specifying Specifics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Smooth Operator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Where Is the Where Clause? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 www.it-ebooks.info [...]... you might have, go to http://www .microsoft. com /learning/ support/search.asp If you have comments, questions, or ideas regarding this book or the companion CD-ROM, please send them to Microsoft Press using either of the following methods: E-Mail mspinput @microsoft. com Postal Mail Microsoft Press Attn: Editor, Microsoft Windows Scripting Self-Paced Learning Guide One Microsoft Way Redmond, WA 98052 Please... coverage of VBScript, Windows Scripting Host, Active Directory Service Interfaces (ADSI), and Windows Management Instrumentation (WMI) is not exceedingly deep This is not a reference book; it is a tutorial, a guide, a springboard for ideas perhaps, but not an encyclopedia Is This Book for Me? Microsoft Windows Scripting Self-Paced Learning Guide is aimed at several audiences, including: ■ Windows networking... after a while too irritating Clearly there needs to be a better way, and there is Scripting is the answer A Practical Approach to Scripting Microsoft Windows Scripting Self-Paced Learning Guide will equip you with the tools to automate setup, deployment, and management of Microsoft Windows 2003 networks via the various scripting interfaces contained with the product In addition, it will provide you... ages—but in the vast majority of the cases, the solution is a simple VBScript In Microsoft Windows Server 2003, enterprise manageability was one of the design goals, and VBScript is one path to unlocking the rich storehouse of newly added fea€ tures Using the techniques outlined in Microsoft Windows Scripting Self-Paced Learning Guide, anyone can begin crafting custom scripts within minutes of opening these... Whereas in the past scripting was somewhat hard to do, required special installations of various implementations, and was rather limited in its effect, with the release of Microsoft Windows XP and Windows Server 2003, scripting is coming into its own This is really as it should be However, most Administrators and IT professionals do not have an understanding of scripting, because in the past scripting was... compatible pointing device ■ Windows Server 2003 or Windows XP www.it-ebooks.info xxiv About This Book Technical Support Every effort has been made to ensure the accuracy of this book and the contents of the companion CD-ROM Microsoft Press provides corrections for books through the World Wide Web at http://www .microsoft. com /learning/ support To connect directly with the Microsoft Press Knowledge Base... components ■ Windows network administrators Anyone desiring to automate the day-today management of Windows NET networks ■ Windows Help Desk staff Anyone desiring to verify configuration of remotely connected desktops ■ Microsoft Certified Systems Engineers (MCSEs) and Microsoft Certified Trainers (MCTs) Although not a strategic core competency within the MCP program, a few questions about scripting do... www.it-ebooks.info www.it-ebooks.info 1 Starting from Scratch In this chapter, you begin your journey down the winding road that leads to the auto­ mation of Microsoft Windows Server 2003 Our first step will be to examine several scripts written in Microsoft Visual Basic Scripting Edition (VBScript) Then you’ll dissect a few scripts so that you can see what elements make up a script Finally—and this is the best part—you’ll... unlock www.it-ebooks.info About This Book xxiii the power of ADSI scripting Appendix C helps you find the special WMI namespaces that enable you to perform many cool “tricks” in your scripting and last but certainly not least is Appendix D, which contains my documentation “cheat sheet”—actually you will want to read it rather early in your scripting career ■ Appendix A, “VBScript Documentation” ■ Appendix... Admin Tools, and Windows Resouce Kit selected tools, and Windows Resource Kit selected tools Sample scripts and starter scripts for all labs System Requirements ■ Minimum 233 MHz in the Intel Pentium/Celeron family or the AMD k6/Atholon/ Duron family ■ 64 MB memory ■ 1.5 GB available hard disk space ■ Display monitor capable of 800 x 600 resolution or higher ■ CD-ROM drive or DVD drive ■ Microsoft Mouse . needs to be a better way, and there is. Scripting is the answer. A Practical Approach to Scripting Microsoft Windows Scripting Self-Paced Learning Guide will equip you with the tools to automate. a guide, a springboard for ideas perhaps, but not an encyclopedia. Is This Book for Me? Microsoft Windows Scripting Self-Paced Learning Guide is aimed at several audiences, including: ■ Windows. or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www .microsoft. com /learning/ . Send comments to mspinput @microsoft. com. Microsoft, Microsoft Press,

Ngày đăng: 24/04/2014, 15:34

Mục lục

  • Cover

    • Copyright

    • Dedication

    • Contents

    • Acknowledgments

    • About This Book

      • A Practical Approach to Scripting

      • Is This Book for Me?

      • Outline of This Book

        • Part 1: Covering the Basics

        • Part 2: Basic Windows Administration

        • Part 3: Advanced Windows Administration

        • Part 4: Scripting Other Applications

        • Part 5: Appendices

        • About the Companion CD

        • System Requirements

          • Technical Support

          • Part I Covering the Basics

            • Chapter 1 Starting from Scratch

              • Before You Begin

              • Running Your First Script

                • Header Information

                • Reference Information

                • Worker Information

                • Output Information

                • Enhancing Your Script

                  • Docs That Make House Calls

                  • Modifying an Existing Script

                    • Modifying the Header Information

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan