ebook img

Automating Windows Administration PDF

821 Pages·2004·22.534 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Automating Windows Administration

Automating Windows Administration STEIN BORGE APress Media, LLC Automating Windows Administration Copyright © 2004 by Stein Borge Originally published by APress in 2004 All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN 978-1-59059-397-4 ISBN 978-1-4302-0731-3 (eBook) DOI 10.1007/978-1-4302-0731-3 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Jim Sumser Technical Reviewer: Eric lippert Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Chris Mills, Steve Rycroft, Dominic Shakeshaft, Jim Sumser, Gavin Wray Project Manager: Beth Christmas Copy Edit Manager: Nicole LeClerc Copy Editor: Nicole LeClerc Production Manager: Kari Brooks Production Editor: Kelly Winquist Compositor: Diana Van Wmkle, Van Wmkle Design Group Proofreader: liz Welch Indexer: Kevin Broccoli Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. To my beautiful wife Alison and children Heidi and Christopher. Contents at a Glance Foreword .................................................................................................................. xv About the Author .............................................................................................. xvii About the Technical Reviewer ..................................................................... xix Acknowledgments ................................................................................................... xx Chapter 1 Introduction ............................................................................... 1 Chapter 2 Shell Operations .................................................................... 39 Chapter 3 Logon Scripts and Scheduling .......................................... 71 Chapter 4 Networking Resources ......................................................... 107 Chapter 5 File Operations .................................................................... 121 Chapter 6 Input/Output Streams ......................................................... 157 Chapter 7 Registry Operations ........................................................... 175 Chapter 8 Regular Expressions ........................................................... 195 Chapter 9 Application Automation ..................................................... 215 Chapter 10 Network Administration/WMI ............................................ 249 Chapter 11 Internet Applications ....................................................... 359 Chapter 12 Messaging Operations ........................................................ .403 Chapter 13 Data Access .............................................................................4 77 Chapter 14 System Administration ....................................................... 575 Chapter 15 Internet Information Server .......................................... 655 Chapter 16 Exchange Server .................................................................... 695 Chapter 17 Security ................................................................................... 739 Index ...................................................................................................................... 793 v Contents Foreword .................................................................................................................. xv About the Author .............................................................................................. xvii About the Technical Reviewer ..................................................................... xix Acknowledgments ................................................................................................... xx Chapter 1. Introduction .......................................................................... 1 What Is WSH? ........................................................................................................... 1 COM Automation ....................................................................................................... 2 Version 2. o Features .......................................................................................... 4 Scripting Components ........................................................................................ 12 Streams, Standard Input and Output, and Piping ............................... 35 Additional Resources ........................................................................................ 37 Chapter 2 Shell Operations .............................................................. 39 2.1 Reading the Command-Line Arguments ................................................ 39 2. 2 Reading an Environment Variable ...................................................... .46 2. 3 Creating or Updating an Environment Variable .......................... 48 2. 4 Deleting an Environment Variable ..................................................... 51 2. 5 Running Applications .............................................. ,. ............................... 52 2. 6 Accessing Windows-Related Folders ................................................... 58 2. 7 Creating a Windows Shortcut ................................................................ 60 2.8 Displaying a Message Prompt ................................................................ 63 2.9 Sending Keystrokes to Applications ................................................ 65 Chapter 3 Logon Scripts and Scheduling ............................... 71 3.1 Connecting Network Resources at Logon .......................................... 71 3. 2 Scheduling Scripts ................................................................................... 79 3. 3 Displaying a Logon Message .................................................................. 86 3.4 Performing Operations Based on Group Membership .................... 95 3.5 Creating an Inventory of Computers at Logon ........................... l02 vii Contents Chapter 4 Networking Resources ................................................. 107 4.1. Identifying a User ................................................................................. 107 4.2 Finding an Available Network Drive .............................................. 108 4.3 Mapping Network Drives ......................................................................... 11o 4.4 Migrating File Services from One Server to Another Server. ................................................................................... 112 4.5 Connecting to a Network Printer ..................................................... 115 4.6 Listing Connected Network Printers .............................................. 117 4. 7 Disconnecting Network Printers ....................................................... 118 Chapter 5 File Operations .............................................................. 121 5.1. Determining the Readiness of a Floppy Drive ........................... 122 5.2 Listing the Drives on a System ....................................................... 124 5. 3 Finding the Size· of a User Directory .......................................... 125 5. 4 Determining the Size of a File ....................................................... 127 5. 5 Reading and Changing File Attributes .......................................... 128 5. 6 Determining the Existence of a File or Folder ...................... 131 5. 7 Renaming a File or Folder .................................................................. 132 5. 8 Comparing Files by Version Number ................................................. 133 5. 9 Creating a Folder .................................................................................... 135 5.10 Finding and Deleting Temporary Files ........................................ 137 5 .1.1. Finding Files That Meet Criteria. ................................................ 140 5.1.2 Deleting a Folder ................................................................................. 144 5.13 Copying a File ........................................................................................ 145 5 .1.4 Copying and Moving a Folder ........................................................... 147 5.1.5 Deleting a File ...................................................................................... 148 5.1.6 Creating and Writing to a Text File .......................................... 149 5.1.7 Opening and Reading a File .............................................................. 151 5 .1.8 Updating a Text File ........................................................................... 153 Chapter 6 Input/Output Streams ................................................. 157 6.1. Using Regular Expressions to Filter the Contents of an Input Stream .. ,. ................................................. 157 6. 2 Reading Keyboard Input ......................................................................... 163 6.3 Generating Template-Based Data ....................................................... 164 6.4 Creating Multiple-User Prompts ....................................................... 170 viii Contents Chapter 7 Registry Operations .................................................... 175 7.1 Reading a Value from the Registry. ................................................ 176 7.2 Writing a Value to the Registry ..................................................... 180 7. 3 Deleting a Registry Entry .................................................................. 184 7.4 Listing the Registry Key Values ..................................................... 186 7.5 Searching and Replacing Registry Values ................................... 188 7. 6 Accessing the Remote Registry ......................................................... 192 Chapter 8 Regular Expressions .................................................... 195 8.1 Validating a String ............................................................................... 196 8.2 Matching Multiple Patterns ................................................................ 203 8.3 Matching Subexpressions ...................................................................... 206 8.4 Replacing Values ...................................................................................... 211 Chapter 9 Application Automation ............................................ 215 9.1 Creating Formatted Word Documents ................................................. 215 9.2 Identifying Office Documents by Their Properties ................ 227 9.3 Importing Data into Excel .................................................................. 231 9.4 Generating Thumbnail Images for Web Pages ............................... 240 9.5 Building Web Page Rollover Images ................................................. 244 9.6 Generating Electronic Copies of Access Reports .................... 246 Chapter 10 Network Administration/WMI .................................. 249 10.1 Accessing Information about a Computer ................................... 251 10.2 Determining the Role of a Computer ............................................ 263 10.3 Obtaining IP Information .................................................................. 265 10.4 Changing the Location of an NT Dump File ............................... 275 10.5 Setting TCPIIP Information .............................................................. 279 10.6 Inventorying Computer Components ................................................. 288 10. 7 Executing Generic WMI Queries ....................................................... 292 10.8 Changing Environment Variables ..................................................... 298 10.9 Terminating a System Process ......................................................... 300 10.10 Starting an Application on a Remote Computer .................... 304 10.11 Compressing Folders and Files ..................................................... 309 10.12 Copying Files on a Remote Computer .......................................... 312 10.13 Rebooting a Computer ......................................................................... 316 10.14 Checking the Event Viewer for Unauthorized Access ......... 320 10.15 Backing Up Event Viewer Events ................................................... 327 ix Contents 10.16 Processing Event Viewer Events ................................................... 329 10.17 Changing NT Service Account Information ............................... 333 10.18 Changing System Time ......................................................................... 336 10.19 Defragging a Drive ............................................................................. 338 10.20 Listing DNS Resources ...................................................................... 341 10.21 Creating a DNS Zone ...........................................................................3 45 10.22 Modifying DNS Zone Properties ..................................................... 350 10.23 Creating DNS Address ......................................................................... 351 10.24 Deleting DNS Resources .................................................................... 355 10.25 Modifying DNS Addresses .................................................................. 356 Chapter 11 Internet Applications ............................................... 359 11.1 Retrieving HTML Data ........................................................................... 359 11. 2 Displaying HTML ...................................................................................... 364 11.3 Displaying an HTML Logon Message ................................................. 369 11.4 Creating an HTML Form .........................................................................3 73 11.5 Enumerating HTML Elements ................................................................ 378 11. 6 Creating a GUI Menu ............................................................................. 387 11. 7 Transferring Files Using FTP ......................................................... 390 11. 8 Domain Name Resolution ...................................................................... 396 11.9 Pinging a Computer ............................................................................... 398 Chapter 12 Messaging Operations ................................................ .403 12.1 Logging On .................................................................................................4 05 12.2 Determining the Default Profile .................................................. .409 12.3 Sending Anonymous Mail ..................................................................... All 12. 4 Running Message Scripts Using NT Scheduler Service ........ .413 12.5 Creating a Mail Message ................................................................... .416 12.6 Setting Message Properties .............................................................. 417 12. 7 Creating Message Recipients .......................................................... .419 12. 8 Sending the Message ............................................................................. 422 12.9 Using a Command-Line Script to Send E-mail .......................... .426 12.10 Checking the Event Log ................................................................... .432 12.11 Getting Computer Status Notification ..................................... .433 12.12 Using the Performance Monitor Event ....................................... .435 12.13 Attaching Files to a Message ...................................................... .436 12.14 Processing Messages ........................................................................... 439 12.15 Filtering Mail ...................................................................................... 441 12.16 Extracting Attachments ................................................................... .444 X Contents 12.17 Using a WSH Script Mail Agent .................................................... .446 12.18 Retrieving a Folder .......................................................................... .451 12.19 Posting Messages to an Exchange Server Public Folder .. .456 12. 20 Creating Folders ................................................................................. 457 12.21 Copying or Moving Messages ......................................................... ..459 12.22 Copying and Moving Folders .......................................................... .462 12.23 Deleting Messages and Folders .................................................... .464 12. 24 Creating New Message Fields ........................................................ .465 12.25 Retrieving an Address Book Recipient .................................... ..468 12. 26 Creating Recipient Entries .......................................................... .472 12.27 Adding a Distribution List .......................................................... .474 Chapter 13 Data Access ........................................................................ .477 ODBC •.................................•.•........•...........................................................................4 77 OLE DB .............................................................................. ,. .................................... 477 Using AD0 ..............................................................................................................4 78 13.1 Data Source Name Connection Strings ......................................... .480 13. 2 File DSN Connection ............................................................................. 485 13.3 DSN-Less Connection Strings .......................................................... .487 13.4 Opening a Secure Database ............................................................... .492 13. 5 Compacting Access Databases .......................................................... .495 13.6 Querying a Table .................................................................................... 500 13. 7 Opening a Table for Writing ........................................................... 504 13.8 Manipulating a Text File .................................................................. 508 13.9 Accessing Excel Data ........................................................................... 510 13.10 Querying the Index Server .............................................................. 513 13.11 Adding Data ............................................................................................ 515 13.12 Updating Data ........................................................................................ 518 13.13 Accessing HTML Data ........................................................................... 520 13.14 Deleting Data ........................................................................................ 524 13.15 Accessing Internet Resources ....................................................... 525 13.16 Exporting Data ...................................................................................... 535 13.17 Importing Data ...................................................................................... 537 13.18 Executing a Stored Procedure ....................................................... 552 13.19 Executing an Access Parameter Query ........................................ 556 13.20 Processing Multiple Recordsets ................................................... 558 13.21 Modifying Command Results .............................................................. 559 13.22 Returning a Parameter Value from a Stored Procedure ..... 561 13.23 Transaction Processing .................................................................... 571 xi

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.