Tuesday, June 8, 2010

Windows 7 Commands

The list of commands available in the command prompt for Windows 7 is similar to that for Windows Vista. Some commonly used commands and a brief explanation of their functions are given.
Commands in Windows 7

The command prompt that has been in previous versions of Windows is still with us and is not much changed fron Windows Vista. The command line remains a powerful and much used feature by system administrators everywhere. Thus, the old command interpreter cmd.exe has been continued although in a slightly newer version. Several commands are now in the standard list that were formerly available only on servers. New commandsare indicated with an asterisk in the list below. Note that some commands may require administrator privileges. A number of commands involving specialized system or network administration have been omitted.

The commands given below remain in wide use but Microsoft has shifted its corporate emphasis to a new command shell called Powershell that is described on another page. This new command shell is included with Windows 7.
ASSOC Displays or modifies file extension associations.
ATTRIB Displays or changes file attributes.
BREAK Sets or clears extended CTRL+C checking.
BCDBOOT* Used to copy critical files to the system partition and to create a new system BCD store.
BCDEDIT Sets properties in boot database to control boot loading.
CACLS Displays or modifies access control lists (ACLs) of files.
CALL Calls one batch program from another.
CD Displays the name of or changes the current directory.
CHCP Displays or sets the active code page number.
CHDIR Displays the name of or changes the current directory.
CHKDSK Checks a disk and displays a status report.
CHKNTFS Displays or modifies the checking of disk at boot time.
CHOICE Batch file command that allows users to select from a set of options.
CIPHER Displays or alters the encryption of directories [files] on NTFS partitions.
CLIP Redirects output of another command to the Windows clipboard.
CLS Clears the screen.
CMD Starts a new instance of the Windows command interpreter.
CMDKEY Creates, lists and deletes stored user names and passwords or credentials.
COLOR Sets the default console foreground and background colors.
COMP Compares the contents of two files or sets of files byte-by-byte
COMPACT Displays or alters the compression of files on NTFS partitions.
CONVERT Converts FAT volumes to NTFS. You cannot convert the current drive.
COPY Copies one or more files to another location.
DATE Displays or sets the date.
DEFRAG Disk defragmenter accessory.
DEL Deletes one or more files.
DIR Displays a list of files and subdirectories in a directory.
DISKCOMP Compares the contents of two floppy disks.
DISKCOPY Copies the contents of one floppy disk to another.
DISKPART Displays or configures Disk Partition properties. A separte command interpreter with a sub-set of commands.
DOSKEY Edits command lines, recalls Windows commands, and creates macros.
DRIVERQUERY Displays current device driver status and properties.
ECHO Displays messages, or turns command echoing on or off.
ENDLOCAL Ends localization of environment changes in a batch file.
ERASE Deletes one or more files.
EXIT Quits and closes the command shell.
EXPAND Expands one or more compressed files.
FC Compares two files or sets of files, and displays the differences between them.
FIND Searches for a text string in a file or files.
FINDSTR Searches for strings in files.
FOR Runs a specified command for each item in a set.
FORFILES Selects files in a folder for batch processing.
FORMAT Formats a disk for use with Windows.
FSUTIL Displays or configures the file system properties.
FTYPE Displays or modifies file types used in file extension associations.
GOTO Directs the Windows command interpreter to a labeled line in a batch program.
GPRESULT Displays Group Policy information for machine or user.
GRAFTABL Enables Windows to display an extended character set in graphics mode.
HELP Provides Help information for Windows commands.
ICACLS Display, modify, backup, or restore ACLs for files and directories (more here).
IF Performs conditional processing in batch programs.
IPCONFIG Displays all current TCP/IP network configuration values
LABEL Creates, changes, or deletes the volume label of a disk.
MD Creates a directory.
MKDIR Creates a directory.
MKLINK Creates Symbolic Links and Hard Links
MODE Configures a system device.
MORE Displays output one screen at a time.
MOVE Moves one or more files from one directory to another directory.
OPENFILES Queries, displays, or disconnects open files or files opened by network users.
PATH Displays or sets a search path for executable files.
PAUSE Suspends processing of a batch file and displays a message.
POPD Restores the previous value of the current directory saved by PUSHD.
PRINT Prints a text file.
PROMPT Changes the Windows command prompt.
PUSHD Saves the current directory then changes it.
RD Removes a directory.
RECOVER Recovers readable information from a bad or defective disk.
REM Designates comments (remarks) in batch files
REN Renames a file or files.
RENAME Renames a file or files.
REPLACE Replaces files.
RMDIR Removes a directory.
ROBOCOPY Advanced utility to copy files and directory trees
SET Displays, sets, or removes environment variables for current session.
SETLOCAL Begins localization of environment changes in a batch file.
SETX Sets environment variables.
SC Displays or configures services (background processes).
SCHTASKS Schedules commands and programs to run on a computer.
SHIFT Shifts the position of replaceable parameters in batch files.
SHUTDOWN Allows proper local or remote shutdown of machine.
SORT Sorts input.
START Starts a separate window to run a specified program or command.
SUBST Associates a path with a drive letter.
SYSTEMINFO Displays machine specific properties and configuration.
TAKEOWN Allows an administrator to take ownership of a file (more here).
TASKLIST Displays all currently running tasks including services.
TASKKILL Kill or stop a running process or application.
TIME Displays or sets the system time.
TIMEOUT Pauses the command processor for the specified number of seconds.More here.
TITLE Sets the window title for a CMD.EXE session.
TREE Graphically displays the directory structure of a drive or path.
TYPE Displays the contents of a text file.
VER Displays the Windows version.
VERIFY Tells Windows whether to verify that your files are written correctly to a disk.
VOL Displays a disk volume label and serial number.
VSSADMIN Volume Shadow Copy Service administration tool
WHERE Displays the location of files that match a search pattern.
XCOPY Copies files and directory trees.
WMIC Displays WMI information inside interactive command shell.

*New to Windows 7

Useful Tools for Windows XP from the Server 2003 Resource Kit

Useful Tools for Windows XP from the Server 2003 Resource Kit

Many of the command-line tools from the Windows Server 2003 resource kit can be used in Windows XP. Some are described here.

Microsoft provides a large assortment of command-line tools, which can be obtained in a variety of ways. For users of Windows XP Professional, there are three major sources. One set of "native" tools is part of the standard installation and these are listed on another page. A second set, called "support tools", can be installed from a full version of Windows XP Professional or downloaded. These are the subject of this page on the present site. A third set is part of the Windows Server 2003 Resource Kit but are applicable to Windows XP. They can be downloaded here and are the subject of this article.

As would be expected, the Windows 2003 Server tools are intended for large networked systems and many are not appropriate for typical home systems. Nonetheless, many can be useful in a simple system. I have made a somewhat arbitrary selection of those that seem most helpful and discuss them below. Note that some of these tools are actually graphical (GUI) tools that are opened from the command line and this is indicated where it applies. A full list of the tools is available at the Microsoft download site. Once they are installed. the Help and Support Center will contain a list with descriptions and syntax for their use.

Cdburn.exe: ISO CD-ROM Burner Tool

CDBurn is a command-line tool that allows the user to write data images from image files located on the hard drive to a CD. The data image can be any kind of data, even raw data. This tool can also be used to erase CD-RW media.

Chklnks.exe: Link Check Wizard

Link Check Wizard (ChkLnks) is a GUI tool that scans all the link (shortcut) files on a computer to determine whether or not the shortcuts point to existing applications or documents. When Link Check Wizard does not find an associated application or document, the wizard lists that file as a dead link, giving you the option to remove it.

Cleanspl.exe: Spooler Cleaner
Spooler Cleaner (CleanSpl) is a GUI tool that restores the print spooler to its original state. It deletes all print jobs, printers, printer drivers, and spool files on a specified local or remote server.
Creatfil.exe: Create File

CreatFil creates a blank file of a specified size, filled with space characters.
Diskraid.exe: RAID Configuration Tool

DiskRaid is a command-line tool that enables configuration and management of redundant array of independent (or inexpensive) disks (RAID) storage subsystems.

Dvdburn.exe: ISO DVD Burner Tool
DVDBurn is a command-line tool that allows the user to write DVD images from image files located on the hard drive to DVD media. The data image can be created by any program capable of producing DVD image files. You can also use this tool to erase DVD media.

Empty.exe: Free Working Set Tool
Free Working Set Tool (Empty) is a command-line tool that frees the working set of a specified task or process, making those page frames available for other processes.

Iniman.exe: Initialization Files Manipulation Tool
IniMan is a command-line tool that enables you to add, delete, modify, or query sections or keys in an .ini file.

Instsrv.exe: Service Installer
Service Installer (InstSrv) is a command-line tool that installs and uninstalls executable services and assigns names to them.

Kernrate.exe: Kernel Profiling Tool
Kernel Profiling Tool (KernRate) is a command-line tool that is a CPU sample profiler. A sample profiler monitors performance and reports back to the user. KernRate reports on kernel and user-mode processes to provide information about CPU activity. Use KernRate to identify which processes are causing a CPU bottleneck.

Linkspeed.exe: Link Speed
Link Speed is a command-line tool that displays the speed of the connection between computers on a network.

Memmonitor.exe: Memory Monitor
MemMonitor is a command-line tool that monitors the memory a process uses
Memtriage.exe: Resource Leak Triage Tool

MemTriage is a command-line tool that detects a possible resource leak on a running system. MemTriage records process information or current kernel pool information and saves it to a log file.

Now.exe: STDOUT Current Date and Time
Now reads standard input (STDIN) and then displays, on standard output (STDOUT), the current date and time followed by the STDIN. Used alone, it displays the current date and time.

Ntimer.exe: Windows Program Timer
NTimer is a command-line tool that measures how long a program runs. NTimer shows elapsed time, time in user mode, and time in privileged mode.

Oh.exe: Open Handles
Open Handles is a command-line tool that shows the handles of all open windows. OH can also be used to show only information about a specific process, object type, or object name.

Oleview.exe: OLE/COM Object Viewer
OLE/COM Object Viewer (OLEView) is a GUI tool that allows you to manage all Microsoft Component Object Model (COM) classes installed on your computer.

Pathman.exe: Path Manager
PathMan is a command-line tool that adds or removes components from system or user paths.

Pmon.exe: Process Resource Monitor
Process Resource Monitor (PMon) is a command-line tool that displays several measures of the CPU and memory use of processes running on the system. The PMon display appears in the command window.

Printdriverinfo.exe: Drivers Source
Drivers Source (PrintDriverInfo) is a command-line tool that is used to collect information about printer drivers and is primarily used for support purposes.

Qgrep.exe
Qgrep is a command-line tool that is used to search a file or list of files for a specific string or pattern and return the line containing the match. QGrep also allows you to search multiple files and subdirectories. Qgrep is similar to the UNIX tool "grep".

Remapkey.exe: Remap Windows Keyboard Layout
RemapKey is a GUI tool that changes the layout of a keyboard by remapping the scan codes of the keys.

Robocopy.exe: Robust File Copy Utility
A versatile utility for maintaining an identical copy of a folder and its sub-folders in more than one location,

Setprinter.exe: Spooler Configuration Tool
Spooler Configuration Tool is a command-line tool that is used to set configurations of local and remote printers

Sleep.exe: Batch File Wait
Sleep is a command-line tool that causes the computer to wait for a specified amount of time. For use in batch files
Splinfo.exe: Print Spooler Information

SplInfo is a command-line tool that collects information from the print spooler and displays it.

Tail.exe
Tail is a command-line tool that displays a user-specified number of the last lines of a text file, such as a log file, in a console window.

Revealing XCOPY

The syntax and use of the command "Xcopy" is described. Of all the command line executables, Xcopy is one of the most useful for the average home PC user. It provides a powerful and versatile method for copying and backing up files and directories.

Syntax of Xcopy command

Xcopy has a large number of possible switches, which gives the command a great deal of flexibility. The syntax for the command is given by:
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/EXCLUDE:file1[+file2][+file3]...]

Upper case letters have been used above but the command is case-insensitive. A description of the various switches is given in Table I. Note that Windows Vista has an additional switch "/B". The function of this switch is to copy a Symbolic Link itself instead of the target of the link. Windows 7 has added "/J" to use unbuffered I/O for large files.

Table I. Description of switches for the command Xcopy Switch Description

/A Copies only files with the archive attribute set, doesn't change the attribute.

/M Copies only files with the archive attribute set, turns off the archive attribute. Useful in backup.

/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
Useful in backup.

/P Prompts you before creating each destination file.

/S Copies directories and subdirectories except empty ones.

/E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.

/V Verifies each new file. Not used by Windows XP.

/W Prompts you to press a key before copying.

/C Continues copying even if errors occur.

/I If destination does not exist and copying more than one file, assumes that destination must be a directory.

/Q Does not display file names while copying.

/F Displays full source and destination file names while copying.

/L Displays files that would be copied.

/G Allows the copying of encrypted files to destination that does not support encryption.

/H Copies hidden and system files also.

/R Overwrites read-only files.

/T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories.

/U Copies only files that already exist in destination.

/K Copies attributes. Normal Xcopy will reset read-only attributes.

/N Copies using the generated "short" names. May be necessary when copying from
NTFS to FAT16.

/O Copies file ownership and ACL information.

/X Copies file audit settings (implies /O).

/Y Suppresses prompting to confirm that you want to overwrite an existing destination file. May be preset in the COPYCMD environment variable

/-Y Prompts to confirm you want to overwrite an existing destination file.

/Z Copies over a network in restartable mode.

/EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings to be excluded. Tricky to use. See below.

/B Copies a Symbolic Link itself instesd of the target of the link. (Windows Vista/Windows 7)
/J Copies using unbuffered I/O. Recommended for very large files. (Windows 7)
Applications of Xcopy

Xcopy provides an excellent tool for backing up selected folders. With appropriate switches, a variety of backup scenarios can be created. One possible backup configuration would be to copy only those files that have been changed. Here is an example command: xcopy C:\somefolder E:\backupfolder /D /E /C /R /H /I /K /Y This command will copy all files, including those in sub-folders, that are newer in the source folder. It will copy hidden as well as read-only files and will create the destination folder and/or sub-folders if they do not already exist.

The next example shows the use of a wildcard; it collects all files of a given type and copies them into one place. The command xcopy C:\*.mp3 E:\mp3folder /S /I /C > E:\mp3List.txt will collect all MP3 files on the C: drive and copy them to a folder on the E: drive. It also creates a list of the files copied and places the list on the E: drive. This simple command preserves the sub-folder structure. If desired, a more advanced script could be written that places all MP3 files in one folder with no sub-folders.
Excluding files and folders

A useful feature of Xcopy is the ability to exclude certain files and/or folders from being copied by means of the "/Exclude" switch. All names containing a given string of characters can be excluded. Unfortunately, Microsoft's description of the switch is neither a model of clarity nor accurate. In fact, postings on the Internet indicate considerable confusion exists about how to implement this handy feature. Perhaps the list below will help clarify how to use it.

1. The strings contained in the names of the files and/or folders to be excluded are not entered directly in the command switch itself.

2. The entry in the command switch is one or more text files that list the strings to be excluded.

3. The format of the switch is /Exclude:{path}list_of_exclusions.txt Note the colon between Exclude and the name of the file that lists the exclusions. Although more than one exclusion file can be used, stick with one if you can.

4. The name of the file that lists exclusions cannot have spaces. Quoting does not help.

5. Be careful with pathnames. Remember that operations are relative to the working directory for the command prompt. I suggest placing the exclusion list in the top directory of the directories being copied and opening the command prompt in the directory just above the directory and sub-directories to be copied. (Go here if you don't know how to open the command prompt wherever you want.) The various relative paths will then be simple. If you open the command prompt in the default location, things can get complicated.

6. The structure of the exclusions list is one exclusion string per line. Wildcards are not used and do not work. If you want to exclude all files whose names contain ABC, simply place ABC on one line of the exclusion file. If it is being used together with the switch "/S", the exclusion file will apply to sub-directories as well as the main directory.

7. To exclude a particular sub-directory, place its name in the exclusion file with backward slashes before and after its name, viz., \excluded_directory\

8. Use a text editor to create exclusion files. Do not use Microsoft Word or other word processor unless you are careful to create text files. Use ANSI encoding. When I tried UTF-8 encoding, the file did not work.

Exit codes for Xcopy

Many commands issue integer exit codes to indicate the status of the command after it is run. The exit codes for Xcopy are given in Table II. When placed in "If" statements, these error codes can be useful in batch files .
Table II. Exit codes for Xcopy Exit code Description
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed Ctrl+C to terminate xcopy.
4 Various errors including insufficient memory or disk space, an invalid drive name, or invalid syntax.
5 Disk write error occurred.