Windows Command Line Administration Instant Reference. Sybex

John Paul Mueller

Quick & Easy Lookup
Real-World Solutions
Answers On The Spit

e-books shop
Windows Command Line Administration
Instant Reference

About the Author
John Mueller is a freelance author and technical editor. He has writing
in his blood, having produced 86 books and over 300 articles to
date. The topics range from networking to artificial intelligence and from
database management to heads-down programming. Some of his current
books include a Windows command line reference, books on VBA and
Visio 2007, a C# design and development manual, and an IronPython
programmer’s guide. 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 magazines like DevSource,
InformIT, SQL Server Professional, Visual C++ Developer, Hard Core
Visual Basic, asp.netPRO, Software Test and Performance, and Visual
Basic Developer. Be sure to read John’s blog at
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 John is also setting up a Web site at Feel free to look and make suggestions
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.

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 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 products 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.

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.

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 volunteers helped in ways
too numerous to mention here. I especially appreciate the efforts of Eva
Beattie, Jonathan S. Weissman, and Osvaldo Téllez Almirall who provided
general input, read the entire book, and selflessly devoted themselves
to this project.

Finally, I would like to thank Pete Gaughan, Agatha Kim, Jennifer
Leland, Liz Britten, 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 few years.

Let’s face it, while GUI applications are nice and they do provide
significant levels of hand holding, they’re cumbersome and inefficient.
The command line is an essential part of the administrator
experience—at least, if the administrator wants to go home at night
and spend weekends somewhere other than work. Using the command
line can often provide faster results with far less effort. In addition, the
command line lends itself to easy automation, so you might not need to
manually perform some tasks at all; you can let the computer do them
while you have a cup of coffee and gab with a friend in the next cubicle.
However, no one can memorize every command, or even a significant
subset of them, so Windows Command-Line Administration Instant
Reference provides you with a quick reference for the common commands
and provides examples of their use to help you avoid potential
errors. In short, if you want to spend time doing something other than
adding users to the server, you need this book!

Work Faster and More Efficiently
Have you looked at the Administrative Tools folder of the Control Panel
lately? It typically contains fourteen or more links to consoles that you
use to administer Windows using a GUI. Finding the right console isn’t
always straightforward. For example, most people would be tempted
to look for hardware settings in System Configuration, but they really
appear in Computer Management. Some of the consoles don’t even
appear in the Administrative Tools folder. A typical Windows setup
includes 21 consoles, so one-third of the consoles are missing—you
need to know they exist in order to use them. If you want to set a group
policy, you need to know that you have to use GPEdit.MSC (the Group
Policy Editor) to change them, but don’t count on Windows helping you.
In short, the GUI is disorganized and difficult to use. On the other hand,
if you want to use the command line, you open one item—the command
prompt. How much simpler can things get?

Speaking of group policies, it requires a single command at the
command line to change any group policy. Yes, changing the policy
requires that you create the command, but there is help to do that.
Changing a policy such as a Domain Profile for Windows Firewall
using Group Policy Editor, however, requires that you dig down six
levels, figure out which of the policies will actually do what you want,
and then perform upward of five additional steps in order to change
the policy. Now, imagine that you have to change a lot of policies on
a number of machines. When working with the command line, you
can create a batch file that performs the task on every machine on
your network. The batch file will likely require an hour or so to create
and test, while using the GUI may very well require days because the
Group Policy Editor lacks automation.

The command line is great for more than just changing settings.
Have you ever wanted to discover all of the files associated with a
particular application and been frustrated in your efforts? The command
line supports a nifty utility called FindStr that lets you look
inside files for copyright statements and other strings. If you have some
idea of what to look for, FindStr will faithfully search every file on the
hard drive for that string—no matter where the file might appear. You
can’t even perform this task using the GUI because Microsoft thinks it
knows better than you how to find things. The GUI doesn’t even index
the inside of every file, just those that Microsoft thinks you should
search. In short, if you want to find anything anywhere, you need the
command line, not a GUI.

It would be easy to go on and on about the benefits of the command
line, but you have an entire book to convince you of the incredible
value of using the command line in place of the GUI in most situations.
Of course, every good thing comes with caveats and the command
line is no different. The command line does require that you be
able to type commands accurately in order to obtain accurate results.
That’s why you need Windows Command-Line Administration
Instant Reference. This book uses a task-based approach to make
it easy for you to type just the command you need. It’s packed with
hundreds of example commands, some of which will meet your needs
with little or no change. If you want to get more out of your day,
you need to use the command line with Windows Command-Line
Administration Instant Reference.

Goals for Writing This Book
I want you to be able to get started using the command line today to
perform useful work. Starting with the first chapter you’ll find that you
can immediately begin using the command line to work faster and more
efficiently. Suddenly, the system that felt so slow just a few minutes earlier
will accomplish work quickly because you’ll take command using a
time proven interface. The first and most important goal of this book is
to get you to work now.

Most people don’t realize the immense number of commands and
utilities available at the command line. In fact, there are commands
and utilities to perform some extremely esoteric tasks and you won’t
see them covered in this book. Instead, this book exposes you to the
commands and utilities that you’ll commonly use; 149 of them. That’s
right! You have access to 149 commands and utilities that can make it
faster and more efficient to administer the systems under your control.
Some of these commands and utilities, such as Windows Management
Interface Command line (WMIC) are so powerful that you might decide
never to use the GUI again. The second goal for this book is to expose
you to the most useful commands and utilities that the command line
has to offer. Look at Appendices A and B to see lists of these commands and utilities.

Automation is one of the major benefits of working at the command
line. If you need to perform a particular task often, there isn’t
any reason to keep doing it manually when you can tell the computer
to perform the task for you instead. Using a GUI makes many people
think that it’s normal to manually perform the same repetitious work
over and over again until your eyes glaze over and you fall asleep out of
sheer boredom. Work shouldn’t be boring and the automation that the
command line can provide relieves you of boredom. Many administrators
have the mistaken idea that they have to become programmers to
use automation, but this book shows you that you can create perfectly
acceptable batch files to automate tasks without becoming even close
to a programmer. So the third major goal of this book is to help you
understand how automation comes into play using batch files.

Of course, you may find that batch files are limited and after working
with batch files for a while, you might decide that a little programming
isn’t so bad after all. The fourth goal of this book is to demonstrate
that scripting is not only powerful, but that it isn’t very hard either.

Imagine how nice it would be to get all of your work done in half or
even a quarter of the time you do now. Working at the command line
and using the full scope of automation it can provide will help you move
toward that goal. So, the final goal for this book is to help you understand
the benefits of scripting. You won’t actually learn how to script
using this book—that’s the topic of another tome, but you’ll get enough
information to decide whether scripting is right for you. In addition,
you’ll see some pretty nifty scripts that will definitely save you time.

Who Should Read This Book?
This book is designed to meet the needs of administrators who are tired
of letting the GUI slow them down and who want the productivity
advantage of working at the command line. More and more administrators
are moving to the command line because it lets them perform tasks
quickly. In addition, the command line lends itself to automation, so
that you don’t spend hours performing precisely the same boring task
over and over again.

Power users will also appreciate this book because it gives them the
edge needed to work quickly in today’s competitive market. There isn’t
any reason to spend hours mousing about when you can complete the
task in a matter of seconds at the command line. For that matter, by
using some of the scheduling techniques found in this book, you can
automate some tasks completely so that you won’t actually perform
them manually again. This book is all about letting the computer do
as much for you as it possibly can so you can spend more time watching
the game, reading a book, or doing something else that’s a bit more
interesting than sitting in front of the computer.

I’m assuming that you already know how to use Windows quite well
and that you’ve performed administration tasks in the past. This book
presents you with instructions for performing common tasks at the
command line and the information you need to customize these tasks to
meet your specific needs. However, the complete novice won’t be able to
keep up with the pace of this book.

What You Need to Use This Book
You’ll very likely want to set up a test machine when working through
the examples in this book. A production machine simply isn’t the right
environment in which to learn how to work at the command line. I used
Windows 7 and Windows Server 2008 while writing this book. If you
have some other version of Windows, you may find that your system
doesn’t have some of the features I discuss. You’ll still find plenty to interest you.

I recommend that you set up the hardware required for a twomachine
network as part of your test setup. Otherwise, you really won’t
see how some of the client-side tasks are supposed to work. Using a
virtual machine setup may work acceptably, but I opted for using two
physical machines so that the interactions would work just as they do
on your network. There are advantages to using two physical machines,
because virtual machines sometimes lack the differences in environment
that two physical machines provide.

The book contains descriptions of numerous utilities that you can
download and use free for the most part. You may prefer other utilities,
but I used these utilities to create the content for the book. If you find a
technique useful, download the utility that goes with it and try it too.
I’m always on the lookout for new utilities, so please be sure to tell me
about your utilities at

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 particular text element means.


e-book sshop

Purchase Now !
Just with Paypal

Product details
 File Size
 5,149 KB
 578 p
 File Type
 PDF format
 2010 by Wiley Publishing, Inc 

Table of Contents
Introduction xix
Part I: Command Line Basics 1
Chapter 1: Configuring the Local Machine 3
Configure the Command Window 4
Set the Window Options 4
Change the Font 7
Choose a Window Layout 8
Define the Text Colors 9
Set the Environment 10
Manage Environment Variables with the Set Command 10
Manage Environment Variables with the SetX Utility 13
Perform Common Tasks 16
Clear the Display 16
Determine the Operating System Version 16
Start an Application 16
Work with Services 18
Shut Down the System 19
Obtain Command Line Help 20
Chapter 2: Making Remote Connections 23
Configure the Remote System 24
Change Security and Basic Setup 25
Setup Remote Administrator 28
Use the Remote Desktop Connection Application 30
Create a Connection 30
Use a Saved Connection 35
Set the Display 35
Access Local Resources 36
Run a Configuration Program 38
Optimize Performance 38
Terminate a Session 39
Use the Start Menu 40
Use the Logoff Utility 40
Chapter 3: Automating Tasks 41
View and Manage Tasks Using Scheduled Tasks 42
Configure the Task Scheduler 43
View Tasks 44
Create New Tasks 46
Delete Existing Tasks 50
Manage Tasks Using the SchTasks Command 51
Use the /Create Switch 51
Use the /Delete Switch 53
Use the /Query Switch 53
Use the /Change Switch 54
Use the /Run Switch 54
Use the /End Switch 54
Part II: Managing Data 55
Chapter 4: Working with File and Directory Objects 57
Manage Directory Objects 58
Find Directories 58
Find Directories Using Patterns 59
View the Current Directory 60
Change the Current Directory 60
Create Directories 61
Move Directories 61
Rename Directories 61
Remove a Directory 62
Display a Directory Structure 62
Manage File Objects 63
Find Files 63
Find Files in Sorted Order 64
Find Files by Attribute 65
Find Files Using Patterns 66
Copy Files 68
Perform Bulk File Transfers 69
Remove Files 70
Move Files 71
Rename a File 71
Set File Attributes 71
Work with File Associations and Types 72
Determine File Associations 72
Create File Associations 73
Determine File Types 73
Create File Types 73
Make Data Links 74
Create Simple Hard Links 75
View Simple Hard Links 75
Delete Simple Hard Links 75
Create Hard Links Using the New Technique 76
Create Symbolic Links 76
Create Junctions 77
Chapter 5: Administering File and Directory Content 79
Execute Applications Anywhere 80
View Application Paths 80
Set Application Paths 80
Locate Information in Files 81
Find Simple Strings 81
Find Complex Strings 82
Display Files Containing Strings 82
Perform Case Insensitive Searches 83
Monitor the File System with the FSUtil Command 83
Control File System Behavior 83
Manage the Volume Dirty Bit 86
Obtain the File System Information Using FSInfo 87
Manage Quotas 88
Repair File System Errors 90
Display Data Files 92
Display a Data File on Screen 92
Employ Data Redirection 92
Display Data One Page at a Time 95
Chapter 6: Managing the Hard Drive 99
Save Hard Drive Space 101
Compress Data 101
Uncompress Data 102
View Compression Status 102
Manage the Volume 102
Get Volume Information 103
Manage Volume Labels 103
Format a Disk 103
Mount a Volume 104
Maintain the Volume 106
Determine File and Directory Status 106
Locate Bad Sectors 107
Perform Boot-Time Disk Checks 108
Improve Disk Access Performance 109
Manage Partitions 110
Start DiskPart 110
List the Objects 111
See Object Details 112
Select an Object 113
Rescan a Computer for Objects 114
Create a Partition 114
Create a Volume 116
Clean a Drive 117
Mark a Partition as Active 117
Mark a Partition as Inactive 118
Assign a Drive Letter 118
Remove a Drive Letter 119
Extend a Volume 119
Delete an Object 120
Exit DiskPart 120
Chapter 7: Securing the Data 121
Protect Data 122
Encrypt a File or Directory 122
View Encrypted Files and Directories 123
Encrypt Hidden Files 124
Back Up Recovery Keys and Certificates 125
Add a User to a File or Directory 125
Remove a User from a File or Directory 126
Decrypt a File or Directory 127
Change File and Directory Access 127
Obtain the DACL 127
Find an SID 130
Grant Permission 130
Deny Permission 131
Remove Permission 131
Set the Owner 132
Verify Security 132
Detect Shared Open Files 132
Use the Query Option 132
Use the Disconnect Option 133
Use the Local Option 134
Take Ownership of Files 134
Set Administrator Ownership 134
Set Other User Ownership 135
Part III: Managing the Network 137
Chapter 8: Managing the Network 139
Get the Media Access Control Information 140
Interact with the Network Using the Net Utility 141
Manage Users 141
Manage Accounts 143
Manage Domains and Local Groups 146
Manage Computers 149
View and Close Sessions 149
Perform Server Configuration 151
View Workstation Configuration 153
Manage Services 153
Manage Files 155
Obtain Help for the Net Utility 156
Manage Print Jobs 157
Manage Resources 158
Obtain Statistics 161
Configure Time Synchronization 163
Chapter 9: Working with TCP/IP 165
Manage the Internet Protocol 166
Display the IP Information 166
Renew Addresses for an Adapter 168
Clear the DNS Resolver Cache 168
Renew DHCP Addresses and Register DNS Names 169
Release a Connection 169
Use Basic Diagnostics 170
Check Connections 170
Trace Transmission Paths 171
Track the Network Path 172
Perform Detailed Network Diagnostics 173
Obtain a Copy of NetDiag 174
Perform a Test 175
Understand Diagnostics 175
Locate and Fix Minor Problems 177
Get Network Statistics 177
Display All Connections and Ports 177
Display Application Statistics 178
Display Ethernet Statistics 179
Display Protocol Information 179
Set a Refresh Interval 180
Manipulate the Network Routing Tables 180
Print the Routing Tables 180
Add a New Route 181
Change a Route 182
Delete a Route 183
Chapter 10: Creating System Connections 185
Perform Remote System Management 186
Create Remote Connections 186
Set Up a Telephony Client 190
Perform Remote Windows Management 191
Execute Commands on a Remote System 206
Work with Terminal Server 206
Obtain Process Information 206
Get Session Information 207
Terminate a Session 208
Disconnect an Active Session 208
End Processes 208
Shut Down the Terminal Server 209
Part IV: Interacting with Active Directory 211
Chapter 11: Configuring Directory Services 213
Manage Directory Services Using the WMIC NTDomain Alias 214
List the Objects 215
List Object Properties 215
Get an Object Property 216
Set an Object Property 217
Query an Association 217
Manage Active Directory with the DSQuery Utility 218
Interact with Servers 218
Interact with Users 220
Interact with Computers 223
Interact with Contacts 223
Interact with Groups 223
Interact with Organizational Units 224
Manage the Active Directory Database 225
Issue a Command 225
Use a Stream 226
Chapter 12: Working with Directory Objects 229
Create New Objects 230
Add a Computer 230
Add a Contact 231
Add a Group 233
Add an Organizational Unit 234
Add a User 234
Get Objects 238
List Computers 238
List Contacts 239
List Groups 240
List Organizational Units 241
List Servers 241
List Users 242
Edit Existing Objects 243
Modify Computer Data 244
Modify Contact Data 245
Modify Group Data 246
Modify Organizational Unit Data 246
Modify User Data 246
Move Existing Objects 248
Delete Existing Objects 248
Part V: Performing Diagnostics 251
Chapter 13: Monitoring System Events 253
Create Simple System Events 254
Trigger System Events 257
Create an Event 258
Delete an Event 261
Query an Event 261
Manage Event Information 262
Display a List of Publishers 262
Get a Publisher 262
Enumerate the Logs 263
Query Log Events 264
Get a Log 267
Get Log Status Information 267
Set a Log 267
Export a Log 269
Archive a Log 270
Clear a Log 270
Chapter 14: Monitoring System Performance 271
Add Performance Counters 272
Load a Performance Counter 272
Save Performance Counter Settings 273
Restore Performance Counter Settings 273
Manage Performance Logs and Alerts 274
Create a Performance Log 274
Start Collecting Data 276
Stop Collecting Data 276
Query a Collection 277
Update a Collection 277
Delete a Collection 278
Create New Performance Logs from Existing Logs 278
Remove Performance Counters 281
Convert Event Trace Logs 281
Part VI: Performing Maintenance 283
Chapter 15: Performing Basic Maintenance 285
Configure the Server 286
Understand the SQL Syntax of WMIC 287
Use Aliases in WMIC 290
Get Help in WMIC 302
Format Data in WMIC 306
Translate Data in WMIC 310
Activate Windows 311
Perform an Activation 311
Display the Activation Information 312
Change the Product Key 312
Manage the System Time 312
Update the Time 313
Configure a Time Source 313
Obtain Time Settings Information 314
Manage the Boot Configuration 315
Enumerate the Configurations 315
Get BCDEdit Help 316
Edit an Existing Boot Setting 317
Change the Boot Sequence 318
Set the Default Boot Item 318
Chapter 16: Managing System Users 319
Audit User Access 320
List the Policies 321
Get a Policy 322
Set a Policy 326
Perform a Backup 327
Perform a Restore 327
Clear an Audit Policy 328
Remove an Audit Policy 328
Work with Group Policies 328
Obtain Group Policy Results 328
Manage Group Policies 330
Obtain Session Status Information 331
Get Process Information 331
Get Session Information 331
Get User Information 332
Get Terminal Server Information 332
Get the User’s Identity 332
Obtain User Logon Information 333
Discover User Identity 333
Chapter 17: Securing the System 335
Add Virus and External Intrusion Protection 337
Remove Viruses 337
Detect and Remove Malicious Software 338
Verify System Files 339
Verify Drivers 340
Change the Verifier Settings 342
Configure Local Security Policies 344
Perform an Analysis 344
Configure Security Policies 345
Export Policies 345
Import Policies 346
Validate a Policy File 346
Work with General Applications 347
Use TaskKill and TaskList Filters 347
Terminate Tasks 350
List Applications 350
List Services 351
Chapter 18: Interacting with the Registry 353
Perform Basic Registry Tasks 354
Export a Registry Key 356
Import a Registry Key 357
Delete a Registry Key 357
Save the Registry 358
Restore the Registry 358
Use the SCRegEdit Script 358
Set Automatic Updates 359
Enable Terminal Services 359
Configure the IP Security (IPSec) Monitor 360
Manage the DNS Service Priority and Weight 361
Use the Command Line Reference 361
Manage the Registry 362
Understand the Registry Settings 362
Query a Registry Entry 363
Add a Registry Entry 364
Delete a Registry Entry 365
Copy a Registry Entry 366
Compare Registry Entries 366
Export Registry Entries 367
Import Registry Entries 367
Restore Registry Entries 368
Part VII: Creating Batch Files 369
Chapter 19: Changing the Batch File Environment 371
Use the CMD Switches 372
Configure the Command Interpreter in the Registry 375
Use Command Extensions 377
Modify Config.NT 380
Use ANSI.SYS to Control the Environment 382
Set the Command Interpreter Location 382
Run Character Mode Applications Only 383
Display the Config.NT Commands 383
Control the Expanded Memory EMM Entry 383
Set the Number of Accessible Files 384
Control Extended Memory with HIMEM.SYS 385
Modify AutoExec.NT 387
Set the Code Page Number with the CHCP Utility 387
Add DPMI Support Using the DosX Utility 388
Enable Graphics Character Support with the GrafTabl Utility 389
Save Memory Using the LH Command 389
Install the Network Redirector Using the ReDir Utility 389
Chapter 20: Working at the Command Prompt 391
Redirect Command Line Output to the Clipboard 392
Manage Usernames and Passwords 393
Display Usernames 393
Create Users 394
Delete Users 394
Change Screen Colors 395
Configure the System Date 396
Configure the System Time 396
Change the Command Window Title 397
Chapter 21: Creating and Testing Batch Files 399
Use Batch File Commands 400
Employ the Call Command 401
Employ the Choice Command 403
Employ the Echo Command 406
Employ the Exit Command 406
Employ the ForFiles Utility 407
Employ the For Command 409
Employ the GoTo Command 414
Employ the If Command 414
Employ the Pause Command 418
Employ the Prompt Command 418
Employ the Rem Command 419
Employ the TimeOut Utility 420
Test Batch Files 420
Add Debug Information to Batch Files 421
Identify Batch Files and Their Actions 425
Use a Centralized Data Store 428
Store and Retrieve Directories with the PushD and PopD Commands 430
Part VIII: Creating Scripts 433
Chapter 22: Discovering Scripting Basics 435
Use Scripting Languages 436
Learn the Basics of JavaScript 436
Learn the Basics of VBScript 438
Use the Windows Scripting File 439
Execute Scripts 442
Run Scripts with the CScript and WScript Utilities 442
Configure the Host and Property Page Options 444
Chapter 23: Using the Scripting Objects 447
Use the WScript Object 449
Use the WScript Properties 449
Use the WScript Methods 451
Use the WScript.WshArguments Object 454
Use the WScript.WshShell Object 455
Use the WScript.WshNetwork Object 457
Use the WScript.WshNetwork Properties 457
Use the WScript.WshNetwork Methods 458
Create a Basic Script 462
Script the Command Line and System Environment 463
Script the Registry 466
Create .LNK Files 468
Chapter 24: Creating Advanced Scripting Examples 471
Script Registry Entries 472
Script Networking Solutions 473
Discover the NetSH Helper List 473
Get NetSH Help 474
Execute NetSH Commands 476
Understand the Basic NetSH Contexts 476
Use the Root Context Commands 478
Impersonate a User 480
Change the Environment 481
Change Logons, Ports, and Users 481
Enable or Disable Session Logons Directly 482
List COM Port Mappings 482
Modify the Install Mode 482
Map a Network Drive 483
Create a .CSV File 487
Appendix A: Alphabetical Command List 493
Appendix B: Topical Command List 505
Appendix C: Listing of Best Practices 521
Always Verify the Data 522
Real Administrators Use Help 523
Test Your Theories on a Test System 524
Use Batch Files, Scripts, and Written Procedures 525
Make Backups 526
Perform User-Specific Changes during Downtime 526
Index 529


═════ ═════

Loading... Protection Status