46163.book Page iii Monday, February 26, 2007 6:16 PM

Windows® Administration at the Command Line for Windows Vista™, Windows® 2003, Windows® XP, and Windows® 2000

John Paul Mueller

Wiley Publishing, Inc.

46163.book Page ii Monday, February 26, 2007 6:16 PM

46163.book Page i Monday, February 26, 2007 6:16 PM

Windows® Administration at the Command Line

46163.book Page ii Monday, February 26, 2007 6:16 PM

46163.book Page iii Monday, February 26, 2007 6:16 PM

Windows® Administration at the Command Line for Windows Vista™, Windows® 2003, Windows® XP, and Windows® 2000

John Paul Mueller

Wiley Publishing, Inc.

46163.book Page iv Monday, February 26, 2007 6:16 PM

Acquisitions and Development Editor: Thomas Cirtin Technical Editor: Russ Mullen Production Editor: Felicia Robinson Copy Editor: Cheryl Hauser Production Manager: Tim Tate Vice President and Executive Group Publisher: Richard Swadley Vice President and Executive Publisher: Joseph B. Wikert Vice President and Publisher: Neil Edde Book Designers: Maureen Forys, Happenstance Type-O-Rama, Judy Fung Compositor: Craig Woods, Happenstance Type-O-Rama Proofreader: Rachael Gunn Indexer: Nancy Guenther Anniversary Logo Design: Richard Pacifico Cover Designer: Ryan Sneed Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-04616-6 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per- copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianap- olis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services or to obtain technical support, please contact our Customer Care Depart- ment within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Cataloging-in-Publication Data Mueller, John, 1958- Windows administration at the command line for Windows 2003, Windows Vista, Windows XP, and Windows 2000 / John P Mueller. p. cm. ISBN 978-0-470-04616-6 (paper/website) 1. Windows (Computer file) 2. Operating systems (Computers) I. Title. QA76.76.O63M8423 2007 005.4'46--dc22 2007006195 TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Windows and Windows Vista are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. 10 9 8 7 6 5 4 3 2 1

46163.book Page v Monday, February 26, 2007 6:16 PM

This book is dedicated to my long-suffering wife, Rebecca, who has always supported me in my writing— I couldn’t ask for a better friend.

46163.book Page vi Monday, February 26, 2007 6:16 PM

46163.book Page vii Monday, February 26, 2007 6:16 PM

Acknowledgments

Thanks to my wife, Rebecca, for working with me to get this book completed. I really don’t know what I would have done without her help in researching and compiling some of the information that appears in this book. She also did a fine job of proofreading my rough draft and page proofing the result. Rebecca also helps a great deal with the glossary and keeps the house running while I’m buried in work. Russ Mullen deserves thanks for his technical edit of this book. He greatly added to the accuracy and depth of the material you see here. Russ is always providing me with great URLs for new prod- ucts and ideas. However, it’s the testing Russ does that helps most. He’s the sanity check for my work. Russ also has different computer equipment from mine, so he’s able to point out flaws that I might not otherwise notice. A number of people read all or part of this book to help me refine the approach, test the coding examples, and generally provide input that all readers wish they could have. These unpaid volun- teers helped in ways too numerous to mention here. I especially appreciate the efforts of Eva Beattie, who read the entire book and selflessly devoted herself to this project. Matt Wagner, my agent, deserves credit for helping me get the contract in the first place and taking care of all the details that most authors don't really consider. I always appreciate his assistance. It's good to know that someone wants to help. Finally, I would like to thank Tom Cirtin, Felicia Robinson, Cheryl Hauser, and the rest of the editorial and production staff at Sybex for their assistance in bringing this book to print. It’s always nice to work with such a great group of professionals and I very much appreciate the friendship we’ve built over the last seven books.

46163.book Page viii Monday, February 26, 2007 6:16 PM

46163.book Page ix Monday, February 26, 2007 6:16 PM

About the Author

John Mueller is a freelance author and technical editor. He has writing in his blood, having pro- duced 73 books and over 300 articles to date. The topics range from networking to artificial intelli- gence and from database management to heads down programming. Some of his current books include a Windows power optimization book, a book on .NET security, and books on Amazon Web Services, Google Web Services, and eBay Web Services. His technical editing skills have helped over 52 authors refine the content of their manuscripts. John has provided technical editing services to both Data Based Advisor and Coast Compute magazines. He’s also contributed articles to maga- zines like DevSource, InformIT, SQL Server Professional, Visual C++ Developer, Hard Core , asp.netPRO, Test and Performance, and Visual Basic Developer. Be sure to read John’s blog at http://www.amazon.com/gp/blog/id/AQOA2QP4X1YWP. When John isn’t working at the computer, you can find him in his workshop. He’s an avid woodworker and candle maker. On any given afternoon, you can find him working at a lathe or putting the finishing touches on a bookcase. He also likes making glycerin soap and candles, which comes in handy for gift baskets. You can reach John on the Internet at [email protected]. John is also setting up a Web site at http://www.mwt.net/~jmueller/. Feel free to look and make sug- gestions on how he can improve it. One of his current projects is creating book FAQ sheets that should help you find the book information you need much faster.

46163.book Page x Monday, February 26, 2007 6:16 PM

46163.book Page xi Monday, February 26, 2007 6:16 PM

Contents at a Glance

Introduction ...... xxiii

Part 1 • Standard Windows Utilities ...... 1

Chapter 1 • Using the Command Line Effectively ...... 3

Chapter 2 • Completing Data-Specific Tasks ...... 23

Chapter 3 • Discovering the System Status ...... 77

Chapter 4 • Locating Files and Other Resources ...... 121

Chapter 5 • Securing and Monitoring a System ...... 167

Chapter 6 • Using Developer and Low-Level Utilities ...... 247

Part 2 • Using Windows Automation ...... 289

Chapter 7 • Creating CMD and BAT Files ...... 291

Chapter 8 • Working with Scripts ...... 339

Chapter 9 • Scripting for Active Directory ...... 363

Chapter 10 • Using Task Scheduler Effectively ...... 387

Chapter 11 • After Hours Automation Scripting ...... 403

Part 3 • Relying on Third Party Automation...... 433

Chapter 12 • Obtaining Command Prompt Enhancers ...... 435

Chapter 13 • Increasing Productivity at the Command Line ...... 449

Chapter 14 • Editing and Compiling Batch Files and Scripts ...... 461

Part 4 • Working with the .NET Framework Utilities ...... 475

Chapter 15 • Understanding the .NET Framework Versions ...... 477

46163.book Page xii Monday, February 26, 2007 6:16 PM

xii CONTENTS AT A GLANCE

Chapter 16 • Configuring the .NET Framework ...... 489

Chapter 17 • Configuring ASP.NET ...... 513

Part 5 • Windows Vista Special Features Preview ...... 529

Chapter 18 • Using Windows PowerShell ...... 531

Chapter 19 • Working with Windows PowerShell ...... 547

Appendix A • 52 Indispensable Command Line Tricks and Techniques...... 563

Appendix B • A Summary of New and Modified Commands in Vista ...... 569

Glossary ...... 575

Index ...... 597

46163.book Page xiii Monday, February 26, 2007 6:16 PM

Contents

Introduction ...... xxiii

Part 1 • Standard Windows Utilities ...... 1

Chapter 1 • Using the Command Line Effectively ...... 3 Understanding Why the Command Line Is So Important ...... 4 The Command Line Made Easy ...... 6 Using Utilities Directly ...... 6 Writing Scripts ...... 8 Scheduling Tasks ...... 8 Relying on Third Party Utilities ...... 8 Viewing the Commands by Purpose ...... 8 Data Specific ...... 9 System Status ...... 9 File and Resource Management ...... 10 Security and System Monitoring ...... 10 Developer and Low-level Tasks ...... 10 Active Directory ...... 11 Services ...... 11 Task Scheduling ...... 12 Updating Your Current Utilities at the Microsoft Download Center ...... 12 Configuring the Command Window ...... 12 Setting the Window Options ...... 13 Changing the Font ...... 14 Choosing a Window Layout ...... 14 Defining the Text Colors ...... 14 Placing a Command Prompt at Your Fingertips ...... 15 Understanding Internal Commands ...... 17 Vista Changes for the Command Line ...... 17 Understanding User Account Control (UAC) Changes ...... 17 Overcoming UAC Problems ...... 18 Giving Yourself Permission ...... 18 Setting Vista Zones on Network Drives ...... 19 Understanding Vista Doesn't Support Old Commands ...... 20 Getting Started with Command Line Tasks ...... 20

Chapter 2 • Completing Data-Specific Tasks ...... 23 Creating and Modifying Data Files and Directories ...... 24 Opening Remote Directories with the Append Utility ...... 24 Copying Files with the Copy Command ...... 25 Removing Files with the Del and Erase Commands ...... 27

46163.book Page xiv Monday, February 26, 2007 6:16 PM

xiv CONTENTS

Removing a Directory Tree with the DelTree Command ...... 28 Modifying Files with the Edlin Utility ...... 29 Repairing System Databases with the ESEnTUtl Utility ...... 30 Decompressing Files with the Expand Utility ...... 34 Creating Directories with the MD and MkDir Commands ...... 35 Moving Files and Renaming Files and Directories with the Move Command . . . . . 36 Setting and Viewing Application Paths with the Path Command ...... 37 Storing and Retrieving Directories with the PushD and PopD Commands ...... 38 Recovering Lost Files with the Recover Utility ...... 39 Removing a Directory with the RD and RmDir Commands ...... 39 Renaming a File or Directory with the Ren and Rename Commands ...... 40 Replacing Existing Files with the Replace Utility ...... 40 Sorting File Content with the Sort Utility ...... 41 Associating a Folder to a Drive with the Subst Utility ...... 43 Displaying a Directory Structure with the Tree Utility ...... 44 Validating File Operations with the Verify Command ...... 45 Performing Bulk File Transfers with the XCopy Utility ...... 45 Performing Robust File Transfers with the RoboCopy Utility ...... 47 Displaying Data Files ...... 54 Working with Line Printers ...... 54 Printing Data Files with the Print Utility ...... 56 Outputting Data Files with the Type Command ...... 57 Performing a Formatted Printout with Notepad ...... 60 Determining File and Directory Status ...... 61 Determining the Current Directory and Changing Directories with the CD and ChDir Commands ...... 61 Comparing Two Files with the Comp Utility ...... 62 Performing Advanced File Comparison with the FC Utility ...... 62 Working with File Associations and Types ...... 64 Taking Ownership of Files with the TakeOwn Utility ...... 65 Performing Backups with the NTBackup Utility ...... 66 Performing Backups with the WBAdmin Utility ...... 68 Start Backup ...... 69 Get Items ...... 69 Working with ODBC Data Sources ...... 70 Configuring the ODBC Environment with the ODBCConf Utility ...... 70 Creating an ODBC Data Source at the Command Line ...... 72 Managing the Windows Registry ...... 72 Modifying the Registry with the RegEdit Utility ...... 73 Scripting Registry Entries with the RegIni Utility ...... 74 Adding and Removing Servers with the RegSvr32 Utility ...... 74 Getting Started with Command Line Tasks ...... 75

Chapter 3 • Discovering the System Status ...... 77 Getting System Status Information ...... 77 Obtaining Driver Information with the DriverQuery Utility ...... 78 Obtaining DirectX Status with the DXDiag Utility ...... 79

46163.book Page xv Monday, February 26, 2007 6:16 PM

CONTENTS xv

Monitoring the File System with the FSUtil Utility ...... 80 Managing Volume Labels with the Label Utility ...... 92 Determining Memory Status with the Mem Utility ...... 92 Obtaining General System Information with the MSInfo32 Utility ...... 93 Managing Environment Variables with the Set Command ...... 96 Managing Environment Variables with the SetX Utility ...... 98 Determining the Version with the Ver Command ...... 100 Getting Volume Information with the Vol Command ...... 100 Viewing the Volume Shadow Service Data with the VSSAdmin Utility ...... 100 Working with Plug and Play (PnP) ...... 101 Performing Unattended Driver Installation with the PnPUnattend Utility ...... 101 Managing PnP Setups Using the PnPUtil Utility ...... 101 Recording System Status Information ...... 102 Managing System Events with the EventCreate Utility ...... 102 Triggering System Events with the EventTriggers Utility ...... 104 Managing Event Information with the WEvtUtil Utility ...... 106 Working with Performance Information ...... 111 Adding Performance Counters with the LodCtr Utility ...... 111 Managing Performance Logs and Alerts with the LogMan Utility ...... 112 Viewing the Results of Changes with the PerfMon Utility ...... 116 Reconfiguring Performance Logs with the ReLog Utility ...... 116 Tracking Performance with the TypePerf Utility ...... 118 Removing Performance Counters with the UnlodCtr Utility ...... 119 Assessing Your System with the WinSAT Utility ...... 119 Getting Started with Command Line Tasks ...... 120

Chapter 4 • Locating Files and Other Resources...... 121 Locating Files ...... 121 Finding Files and Directories with the Dir Command ...... 122 Finding Files and Directories with the Where Utility ...... 124 Detecting Shared Open Files with the OpenFiles Utility ...... 124 Locating Information in Files with the Find and FindStr Utilities ...... 127 Monitoring Files ...... 129 Changing File and Directory Attributes with the Attrib Utility ...... 130 Changing File and Directory Access with the CACLs Utility ...... 132 Changing File and Directory Access with the ICACLs Utility ...... 134 Determining File and Directory Status with the ChkDsk Utility ...... 136 Performing Boot Time Disk Checks with the ChkNTFS Utility ...... 137 Encrypting Data with the Cipher Utility ...... 139 Compressing Data with the Compact Utility ...... 141 Working with Other Resources ...... 143 Converting Program Groups with the GrpConv Utility ...... 143 Managing Power Settings with the PowerCfg Utility ...... 143 Working with Terminal Server ...... 148 Obtaining Session Status Information with the Query Utility ...... 153 Working with Remote Access Server ...... 155 Setting Up a Telephony Client with the TCMSetup Utility ...... 157

46163.book Page xvi Monday, February 26, 2007 6:16 PM

xvi CONTENTS

Communicating with Telnet ...... 158 Managing the System Time with the W32Tm Utility ...... 161 Getting Started with Command Line Tasks ...... 165

Chapter 5 • Securing and Monitoring a System...... 167 Working with the Network ...... 168 Managing the ATM Call Manager with the ATMAdm Utility ...... 168 Getting the Media Access Control Information with the GetMAC Utility ...... 168 Getting the NetWare Routing Information with the IPXRoute Utility ...... 169 Managing WinHTTP Proxy Configuration with the ProxyCfg Utility ...... 170 Managing the Network with the Net Utility ...... 171 Discovering TCP/IP Diagnostic Tools ...... 184 Managing FTP Servers with the FTP Utility ...... 208 Working with Users ...... 209 Monitoring Users with the AuditUsr Utility ...... 210 Configuring Profiles the CMStP Utility ...... 211 Obtaining Group Policy Results with the GPResult Utility ...... 212 Managing Group Policies with the GPUpdate Utility ...... 213 Sending Messages with the Msg Utility ...... 214 Auditing User Access with the AuditPol Utility ...... 214 Obtaining User Login Information with the QUser Utility ...... 218 Discovering User Identity with the WhoAmI Utility ...... 218 Virus and External Intrusion Protection ...... 219 Removing Viruses with the BlastCln Utility ...... 220 Managing the File System with the FltMC Utility ...... 221 Detect and Remove Malicious Software with the MRT Utility ...... 223 Verifying System Files with the SFC Utility ...... 223 Verifying Drivers with the Verifier Utility ...... 224 Configuring the System Setup ...... 226 Managing the Boot Configuration with the BootCfg Utility ...... 226 Managing the Boot Configuration with BCDEdit in Vista ...... 228 Accessing the WinPE Network Installer with the NetCfg Utility ...... 232 Accessing the Windows with the PkgMgr Utility ...... 232 Configuring Local Security Policies with the SecEdit Utility ...... 233 Adding and Removing Applications with the SysOCMgr Utility ...... 235 Adding and Removing Applications with the OCSetup Utility ...... 235 Getting System Configuration Information with the SystemInfo Utility ...... 236 Interacting with the Internet ...... 237 Converting IIS Logs with the ConvLog Utility ...... 237 Monitoring and Managing IIS with the IISReset Utility ...... 238 Working with IP Version 6 ...... 238 Working with General Applications ...... 240 Terminating Tasks with the TaskKill Utility ...... 240 Listing Applications and Services with the TaskList Utility ...... 242 Converting Event Trace Logs with the TraceRpt Utility ...... 243 Perform System Diagnostics with DispDiag ...... 245 Getting Started with Command Line Tasks ...... 245

46163.book Page xvii Monday, February 26, 2007 6:16 PM

CONTENTS xvii

Chapter 6 • Using Developer and Low-Level Utilities ...... 247 Working with Automated System Recovery ...... 248 Backing Up and Restoring System Data with the ASR_Fmt Utility ...... 249 Working with Logical Disks Using the ASR_LDM Utility ...... 250 Working with Protected Files Using the ASR_PFU Utility ...... 251 Using the Start Command ...... 251 Performing Disk Maintenance ...... 253 Managing Removable Storage with the RSM Utility ...... 253 Converting FAT Partitions to NTFS with the Convert Utility ...... 259 Improving Disk Access Performance with the Defrag Utility ...... 260 Compressing Files with the Diantz and MakeCAB Utilities ...... 261 Managing Partitions with the DiskPart Utility ...... 262 Mounting a Volume with the MountVol Utility ...... 267 Managing Disk Performance with the DiskPerf Utility ...... 268 Managing RAID Setups Using the DiskRAID Utility ...... 269 Employing Low-Level Utilities ...... 269 Examining, Modifying, and Debugging Files with the Debug Utility ...... 269 Converting Executables with the Exe2Bin Utility ...... 270 Ensuring Proper Application Execution with the ForceDOS Utility ...... 270 Terminating a Session Using the Logoff Utility ...... 271 Performing System-Level Debugging with the NTSD Utility ...... 271 Managing Compatibility Databases with SDBInst ...... 275 Accessing Functions within DLLs ...... 276 Uninstalling the Operating System with the OSUninst Utility ...... 277 Controlling Services with the SC Utility ...... 278 Shutting Down the System with the ShutDown Utility ...... 282 Replicating COM+ Applications with the COMRepl Utility ...... 284 Managing Type Libraries with the RegTLib Utility ...... 284 Saving and Restoring System Restore Data with the SRDiag Utility ...... 285 Performing Web-Based Enterprise Management Tasks ...... 285 Administering Managed Object Format Files with the MOFComp Utility ...... 286 Interacting with the WBEM Server with the WinMgmt Utility ...... 287 Tracing WinSxS Behavior with the SxSTrace Utility ...... 288 Getting Started with Command Line Tasks ...... 288

Part 2 • Using Windows Automation ...... 289

Chapter 7 • Creating CMD and BAT Files ...... 291 Starting the Command Interpreter ...... 291 Using the CMD Switches ...... 292 Modifying Config.NT ...... 297 Modifying AutoExec.NT ...... 301 Modifying Application Behavior Using a PIF ...... 305 Defining Application Compatibility with the SetVer Utility ...... 308 Using Common DOS Utilities ...... 309 Working at the Command Prompt ...... 316 Redirecting Command Line Output to the Clipboard with the Clip Utility . . . . . 316 Clearing the Display with the CLS Command ...... 316

46163.book Page xviii Monday, February 26, 2007 6:16 PM

xviii CONTENTS

Managing User Names and Passwords with CmdKey ...... 317 Changing Screen Colors with the Color Command ...... 318 Working with the System Date Using the Date Command ...... 319 Tracking Command Line Actions with the DosKey Utility ...... 319 Obtaining Command Line Help with the Help Utility ...... 321 Working with the System Time Using the Time Command ...... 321 Changing the Command Window Title with the Title Command ...... 322 Creating Batch Files ...... 322 Using the Call Command ...... 323 Using the Choice Command ...... 324 Using the Echo Command ...... 326 Using the Exit Command ...... 327 Using the ForFiles Utility ...... 327 Using the For Command ...... 328 Using the Goto Command ...... 330 Using the If Command ...... 331 Using the Pause Command ...... 334 Using the Prompt Command ...... 334 Using the Rem Command ...... 335 Using the Shift Command ...... 335 Using the TimeOut Utility ...... 335 Using the WaitFor Utility ...... 336 Getting Started with Command Line Tasks ...... 336

Chapter 8 • Working with Scripts ...... 339 Understanding Scripting Languages ...... 339 Learning the Basics of JavaScript ...... 340 Learning the Basics of VBScript ...... 341 Executing Scripts ...... 342 Running Scripts with the CScript and WScript Utilities ...... 342 Configuring the Host and Property Page Options ...... 344 Scripting Networking Solutions with the NetSH Utility ...... 344 Creating a Basic Script ...... 349 Scripting the Command Line and System Environment ...... 350 Scripting the Registry ...... 352 Using the Scripting Objects ...... 354 Working with the WScript Object ...... 355 Working with the WScript.WshArguments Object ...... 356 Working with the WScript.WshShell Object ...... 356 Working with the WScript.WshNetwork Object ...... 358 Impersonating a User with the RunAs Utility ...... 359 Changing the Environment ...... 360 Changing Logons, Ports, and Users with the Change Utility ...... 360 Enabling or Disabling Session Logons with the ChgLogon Utility ...... 361

46163.book Page xix Monday, February 26, 2007 6:16 PM

CONTENTS xix

Listing COM Port Mappings Using the ChgPort Utility ...... 361 Modifying the Install Mode with the ChgUsr Utility ...... 361 Getting Started with Command Line Tasks ...... 361

Chapter 9 • Scripting for Active Directory ...... 363 Discovering Helpful Active Directory Utilities ...... 364 Managing Active Directory with the DSQuery Utility ...... 365 Managing the Active Directory Database with the NTDSUtil Utility ...... 371 Working with Objects ...... 373 Creating New Objects Using the DSAdd Utility ...... 373 Listing Objects Using the DSGet Utility ...... 378 Editing Existing Objects Using the DSMod Utility ...... 382 Moving Existing Objects Using the DSMove Utility ...... 382 Deleting Objects Using the DSRm Utility ...... 383 Working with Users, Groups, and Computers ...... 383 Obtaining a User’s Logon Name ...... 384 Obtaining a User’s Full Name ...... 384 Discovering User Group Membership ...... 384 Resetting a User’s Password ...... 385 Displaying a List of Hostnames ...... 385 Getting Started with Command Line Tasks ...... 385

Chapter 10 • Using Task Scheduler Effectively...... 387 Starting and Stopping the Task Scheduler Service ...... 388 Managing Tasks with the SchTasks Utility ...... 389 Working with the AT Utility ...... 395 Combining the AT Utility with Batch Files ...... 396 Creating Script-Based Scheduler Activities ...... 398 Getting Started with Command Line Tasks ...... 401

Chapter 11 • After Hours Automation Scripting ...... 403 Defining After Hours Task Candidates ...... 403 Creating Message Queue Backups with the MQBkup Utility ...... 405 Installing Applications with the MSIExec Utility ...... 405 Designing and Testing the After Hours Batch File ...... 409 Adding Debug Information to Batch Files ...... 409 Identifying Batch Files and Their Actions ...... 413 Using a Centralized Data Store ...... 415 Designing and Testing the After Hours Script ...... 417 Mapping a Network Drive ...... 417 Creating a CSV File ...... 420 Remote System Management ...... 424 Creating Remote Connections with the MSTSC Utility ...... 424 Performing Remote Windows Management with the WinRM Utility ...... 425 Accessing a System with the WinRS Utility ...... 428 Providing Fault Tolerance for an After Hours Batch or Script ...... 429 Getting Started with Command Line Tasks ...... 431

46163.book Page xx Monday, February 26, 2007 6:16 PM

xx CONTENTS

Part 3 • Relying on Third Party Automation ...... 433

Chapter 12 • Obtaining Command Prompt Enhancers ...... 435 Using XVI32 to View Files in Depth ...... 435 Moving Data with Send To Toys ...... 438 Checking File Integrity Using FCIV ...... 439 Getting the Better XCopy with XXCopy ...... 443 Working with Shell Extensions Using ShellExView ...... 443 Examining Processes Using Process Explorer ...... 445 Getting Started with Command Line Tasks ...... 447

Chapter 13 • Increasing Productivity at the Command Line...... 449 Obtaining Additional Information with ToggIt Command Line Helper ...... 450 Using Quick Shutdown to End a Session Fast ...... 451 Creating a Friendlier Interface with PromptPal ...... 453 Getting a More Functional Command Line with WinOne ...... 454 Automating Email Using sendEmail ...... 455 Viewing XML Files Using XML Notepad 2007 ...... 458 Getting Started with Command Line Tasks ...... 459

Chapter 14 • Editing and Compiling Batch Files and Scripts ...... 461 Editing All File Types with WinVi ...... 461 Obtaining a Better Notepad with Notepad+ ...... 463 Creating Executable Batch Files with Batch File Compiler 5.2 ...... 465 Develop and Compile Batch Files with Quick Batch File Compiler ...... 466 Understanding JavaScript and VBScript Compilers ...... 467 Understanding the JSC Compiler Supplied with .NET ...... 469 Using the JSC Compiler ...... 469 Creating a Simple Example ...... 472 Working with the .NET Framework ...... 472 Getting Started with Command Line Tasks ...... 473

Part 4 • Working with the .NET Framework Utilities ...... 475

Chapter 15 • Understanding the .NET Framework Versions ...... 477 Locating the .NET Framework on Your System ...... 478 Understanding the Concept of Side-by-Side Versions ...... 481 Viewing the Assembly Folder ...... 484 Discovering the Essential .NET Framework Assemblies ...... 486 Getting Started with Command Line Tasks ...... 488

Chapter 16 • Configuring the .NET Framework ...... 489 Understanding .NET Framework Configuration ...... 489 Working with the Global Assembly Cache ...... 490 Understanding .NET Security ...... 490

46163.book Page xxi Monday, February 26, 2007 6:16 PM

CONTENTS xxi

Working with Code Groups ...... 494 Creating and Defining Permission Sets ...... 495 Defining Policy Assemblies ...... 496 Adding Configured Applications ...... 496 Understanding the Use of CONFIG Files ...... 497 Setting Policies Using the CASPol Utility ...... 499 Placing Assemblies in the Global Assembly Cache with GACUtil ...... 502 Installing Assemblies with the InstallUtil Utility ...... 504 Registering Assemblies with the RegAsm Utility ...... 505 Registering Services with the RegSvcs Utility ...... 505 Using the .NET Framework 3.0 Utilities ...... 506 Configuring COM+ Applications with the ComSvcConfig Utility ...... 506 Installing and Configuring Windows Communication Foundation Using the ServiceModelReg Utility ...... 508 Interacting with WS-AtomicTransaction Using the WSATConfig Utility ...... 509 Getting Started with Command Line Tasks ...... 510

Chapter 17 • Configuring ASP.NET ...... 513 Locating ASP.NET Errors ...... 513 Fixing Application Registration Errors ...... 514 Fixing File Association Problems ...... 514 Fixing Configuration Problems ...... 517 Creating Web Applications with the ASPNet_Compiler Utility ...... 518 Providing Multiple Browser Support with the ASPNet_RegBrowsers Utility ...... 519 Adding ASP.NET Support to IIS with the ASPNet_RegIIS Utility ...... 520 Adding ASP.NET Support to SQL Server with the ASPNet_RegSQL Utility ...... 523 Using the Command Line ...... 524 Working with the ASPNet_RegSQL Utility Wizard ...... 526 Understanding the ASPNet_State Service ...... 527 Getting Started with Command Line Tasks ...... 528

Part 5 • Windows Vista Special Features Preview ...... 529

Chapter 18 • Using Windows PowerShell...... 531 An Overview of Windows PowerShell ...... 531 Why Use the Windows PowerShell? ...... 532 Downloading and Installing Windows PowerShell ...... 533 Understanding the Windows PowerShell Difference ...... 533 Using the New Windows PowerShell Commands ...... 536 Getting Started with Command Line Tasks ...... 546

Chapter 19 • Working with Windows PowerShell...... 547 Using the PS Command Interpreter ...... 548 Creating a Shell Extension with the Make-Shell Utility ...... 550 Creating a Windows PowerShell Script ...... 552 Creating a Simple Script ...... 553 Running the Script ...... 556

46163.book Page xxii Monday, February 26, 2007 6:16 PM

xxii CONTENTS

Creating a Windows PowerShell Cmdlet and Shell ...... 558 Creating the Cmdlet Code ...... 558 Compiling the Cmdlet Executable ...... 560 Using the Make-Shell Utility to Create the Shell ...... 561 Getting Started with Command Line Tasks ...... 562

Appendix A • 52 Indispensable Command Line Tricks and Techniques . . . . . 563

Appendix B • A Summary of New and Modified Commands in Vista ...... 569

Glossary ...... 575

Index ...... 597

46163.book Page xxiii Monday, February 26, 2007 6:16 PM

Introduction

When was the last time you visited the command line? A few administrators live there, but many others have forgotten about it over the years. When Microsoft originally introduced Windows, the assumption was that you no longer needed the command line and many people left it behind com- pletely. After all, why bother with the command line when you can access everything you need from the graphical environment? The problem is that the Windows graphical user interface (GUI) doesn’t actually provide access to everything on your system. In addition, all of that mousing around wastes considerable time and effort. You can’t easily replicate your actions either; many people have tried, and failed, to produce a macro recorder for the graphical portion of Windows. Every time that you want to perform a task, you start it from scratch, which means that you have plenty of opportunities for making mistakes. Windows Administration at the Command Line reveals the command line to you. Using the information in this book, you not only discover the vast array of commands that are at your disposal but you also see how to automate those commands so that you can save significant time and effort while performing administrative tasks. Just in case you thought that the command line would go away in Vista in favor of Windows PowerShell, you should look at all of the command line changes in this edition of the book. In fact, you’ll find the special icon shown at the beginning of this paragraph throughout the book to show just how many changes Microsoft has made to the command line in Vista. If you want a summary of the changes, check out Appendix B. The command line is alive and well in Vista. Not only is Microsoft supporting it, but you’ll find a wealth of updates as well. Make sure to read about Windows PowerShell in Chapters 18 and 19 though—future versions of Windows will very likely move toward this new environment for administrators. No matter which com- mand line interface you choose, Windows Administration at the Command Line provides the resources you need to work effectively and efficiently.

Overcoming GUI Problems As an example of the flawed behavior of the GUI, just try locating the word Microsoft in the execut- ables on your hard drive. You’ll find that the task is impossible because Windows doesn’t search executables and just barely searches data files. Many people have complained about the flawed per- formance of the search mechanism in Windows. Many people end up getting third party utilities to help them search for the data that Windows should help them find, utilities with dubious reputa- tions for compromising security. Windows Administration at the Command Line shows you a better way, one that relies on a free utility supplied with Windows that will never divulge your personal information to anyone else. Check out the FindStr utility in Chapter 4 and you’ll discover the high- speed search mechanism used by people in the know. The FindStr utility is but one of hundreds of commands and utilities discussed in this book. Just think about what you can do with all of those free

46163.book Page xxiv Monday, February 26, 2007 6:16 PM

xxiv INTRODUCTION

resources! Not only will you accomplish your work faster and with fewer errors, but by reading this book, you can save your company a significant investment in third party products that might not do the job anyway. No other book has the level of detail provided by Windows Administration at the Command Line. I scoured the Internet looking for all of the details about every Windows command and utility I could find. In some cases, the information you see in this book appears nowhere else. Much of the extra information in this book is the result of 20 years of hard won experience at the command line starting with DOS and moving through the current version of Windows. This book gives you the benefit of the experience of many network administrators as told on their Web sites and through correspondence in email. This book offers something for everyone. Everyone needs to locate files on their hard drive. If you think the GUI is going to help you, think again. After a few frustrating searches, you’ll wish for a better tool and you already have it in the form of the Dir command. Unlike the Windows GUI, the Dir com- mand actually locates the files you request on the hard drive. The interesting thing is that the Dir command is very easy to use. Anyone can employ this command with very little training. In fact, I included Chapter 1 of this book for those who have little or no experience with the command line. Chapter 1 helps you discover techniques for using the command line effectively and configuring it to meet your specific needs. Even if you’re a complete command line novice, you can use this book to get started by reading Chapter 1 first and becoming familiar with the command line.

Goals for Writing This Book My initial goal for writing this book was to overcome the frustration of using the command line. I constantly had to look up commands on the Internet because I couldn’t find a single resource that answered all of my command line questions. After performing some research online, I found that many other developers, administrators, and even average users were just as frustrated as I was. Con- sequently, writing a book about the command line seemed like an ideal way to help everyone. This book is the result. Never again will you spend hours looking for the right answer to a command line question; you’ll find them here. Of course, documenting the command or utility usually isn’t enough. It’s important to know all of the caveats of using the command or utility and answer questions such as how much damage it could cause to a system. In many cases, you also need additional common information, such as a cultural identifier. Consequently, as I wrote the book, I tried to provide as many tidbits of addi- tional information as I could. These tidbits turn the documentation entries from functional into truly useful. You’ll also find a wealth of Real World Scenarios in this book. Each of the Real World Scenarios tells you about the commands or utilities in general from a real world perspective. All of the stories in these sections are real. Some of them did happen to me; many others didn’t. I did change the names of those involved to protect the innocent. The point of all these Real World Scenarios is to provide you something that simple documentation can’t: a perspective of why you should care about a command or utility and how you can use it safely. Along with all of the other documentation, I wanted to share a few of my favorite techniques for working at the command line. You’ll find scripts that I have used for many years in this book to per- form work at the command line. The batch files and scripts have seen real world use and you can use them too. Copy the scripts or batch files out of the book and use them as is, or modify them to meet your specific needs.

46163.book Page xxv Monday, February 26, 2007 6:16 PM

INTRODUCTION xxv

Who Should Read This Book? Anyone can read this book. In fact, the first five chapters of the book are useful for anyone who uses Windows regardless of experience level. The amazing array of commands that Windows hides at the command prompt will give you the tools you require to get more work done with a lot less effort. Gone are the frustrations of using graphical tools that simply don’t work most of the time. I did anticipate a certain level of knowledge for even the novice command line user. You should have a good idea of how to work with Windows. For example, you might want to think twice about using the commands in this book if you don’t know how to perform a search of the hard drive using Windows. In addition, you should be familiar with the mouse and relatively well acquainted with the keyboard. This book doesn’t teach Windows basics—it goes right to the command line and helps you to start working there immediately. However, some command line information might not make as much sense if you don’t already have at least some Windows experience. Starting with Chapter 6 and moving on to Chapter 17, this book is targeted toward the needs of developers and administrators. The average user will never require the commands listed in Chap- ter 6. In fact, developers and administrators will use them only on occasion. These powerful com- mands help you perform tasks that you generally can’t perform using the GUI. In fact, you’ll even find a section that describes a technique for accessing Microsoft’s secret functions within the Win- dows DLLs. See the “Accessing Functions within DLLs” section of Chapter 6 for details. Developers and administrators also need to automate tasks in today’s hectic IT environment. Chapters 7 through 11 help you get the most out of Windows automation features, which are actu- ally quite formidable once you know how to use them. Should Windows fail to provide some func- tionality, Chapters 12 through 14 provide tips and hints on third party applications you might want to use. Chapters 15 through 17 provide an all-important view of the .NET Framework. Did you know that you can compile JScript using the .NET Framework? Most people don’t know about this feature because Microsoft hasn’t advertised it. Without spending a single penny, you can create your own JScript executable that can take full advantage of the .NET Framework. Check out this technique in the “Understanding the JSC Compiler Supplied with .NET” section of Chapter 14. Chapters 18 and 19 provide a preview of what Vista looks like at the command line. All I can say after working with Vista and Windows PowerShell for a while is wow (you can download Win- dows PowerShell for other versions of Windows as well and I tell you how to do it)! What you’ll see in these chapters is going to amaze you. Vista and Windows PowerShell represent a significant and long anticipated departure from the command line of the past. Yes, you can still use all of the older techniques in this operating system, but the new features are going to amaze you with their ability to get work done quickly, efficiently, and with fewer potential security issues. You get all this and better documentation besides. Windows PowerShell is a fully extensible command line shell, very much in the same vein as UNIX shells, only a lot more powerful.

Conventions Used in This Book It always helps to know what the special text means in a book. The following table provides a list of standard usage conventions. These conventions make it easier for you to understand what a par- ticular text element means.

46163.book Page xxvi Monday, February 26, 2007 6:16 PM

xxvi INTRODUCTION

Table I.1: Standard Usage Conventions Convention Explanation

Inline Code Some code will appear in the text of the book to help explain application functionality. The code appears in a special font that makes it easy to see. This monospaced font also makes the code easier to read.

Inline Variable As with , variable source code information that appears inline will also appear in a special font that makes it stand out from the rest of the text. When you see monospaced text in an italic typeface, you can be sure it’s a variable of some type. Replace this variable with a specific value. The text will always provide examples of specific values that you might use.

User Input Sometimes I’ll ask you to type something. For example, you might need to type a particular value into the field of a dialog box. This special font helps you see what you need to type.

Filename A variable name is a value that you need to replace with something else. For example, you might need to provide the name of your server as part of a command line argument. Because I don’t know the name of your server, I’ll provide a variable name instead. The variable name you'll see usually provides a clue as to what kind of information you need to supply. In this case, you'll need to provide a filename. Although the book doesn’t provide examples of every variable that you might encounter, it does provide enough so that you know how to use them with a particular command.

[Filename] When you see square brackets around a value, switch, or command, it means that this is an optional component. You don't have to include it as part of the command line or dialog field unless you want the additional functionality that the value, switch, or command provides.

File  Open Menus and the selections on them appear with a special menu arrow symbol. “File  Open” means “Access the File menu and choose Open.”

italic You’ll normally see words in italic if they have special meaning or if this is the first use of the term and the text provides a definition for it. Always pay special attention to words in italic because they’re unique in some way. When you see a term that you don’t understand, make sure you check the glossary for the meaning of the term as well. The glossary also includes definitions for every nonstandard acronym in the book.

Monospace Some words appear in a monospace font because they’re easier to see or require emphasis of some type. For example, all filenames in the book appear in a monospace font to make them easier to read.

URLs URLs will normally appear in a monospace font so that you can see them with greater ease. The URLs in this book provide sources of additional information designed to make your development experience better. URLs often provide sources of interesting information as well.

46163.book Page 1 Monday, February 26, 2007 6:16 PM

Part 1 Standard Windows Utilities

In This Section: ◆ Chapter 1: Using the Command Line Effectively ◆ Chapter 2: Completing Data-Specific Tasks ◆ Chapter 3: Discovering the System Status ◆ Chapter 4: Locating Files and Other Resources ◆ Chapter 5: Securing and Monitoring a System ◆ Chapter 6: Using Developer and Low-Level Utilities

46163.book Page 2 Monday, February 26, 2007 6:16 PM