To take advantage of the command line and
all its many useful commands, you need to start a command-line session.
Windows Home Server offers a number of ways to get to the command
prompt:
- Select Start, Command Prompt.
- Press Windows Logo+R (or select Start, Run), type cmd in the Run dialog box, and click OK. (You can also click Start, type cmd, and then press Enter.)
- Create a shortcut for %SystemRoot%\system32\cmd.exe on your desktop (or some other convenient location, such as the taskbar), and then launch the shortcut.
- Reboot
your computer, press F8 to display Windows Home Server’s Advanced Boot
Options menu, and select the Safe Mode with Command Prompt item.
Note
It’s also possible to configure Windows Home Server’s
Folder file type to open the command prompt in Windows Explorer’s
current folder.
Running CMD
For the methods that use the CMD executable, you can specify extra switches after the cmd.exe
filename. Most of these switches aren’t particularly useful, so let’s
start with the simplest syntax that you’ll use most often:
CMD [[/S] [/C | /K] command]
/S | Strips out the first and last quotation marks from the command, provided that the first quotation mark is the first character in command. |
/C | Executes the command and then terminates. |
/K | Executes the command and remains running. |
command | Specifies the command to run. |
For example, if your Internet service provider (ISP)
provides you with a dynamic Internet Protocol (IP) address, you can
often solve some connection problems by asking the IP for a fresh
address. You do that by running the command ipconfig /renew at the command line. In this case, you don’t need the Command Prompt window to remain open, so you can specify the /C switch to shut down the command-line session automatically when the IPCONFIG utility finishes:
On the other hand, you often either want to see the
results of the command, or want to leave the Command Prompt window open
so that you can run other commands. In those cases, use the /K switch. For example, the following command runs the SET utility (which displays the current values of the Windows Home Server environment variables) and then leaves the command-line session running:
Here’s the full syntax of cmd.exe:
CMD [/A | /U] [/Q] [/D] [/T:bf] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] command]
/Q | Turns off command echoing. If command is a batch file, you won’t see any of the batch file commands as they’re executed. This is the same as adding the statement @ECHO OFF at the beginning of a batch file. |
/D | Disables the execution of AutoRun
commands from the Registry. These are commands that run automatically
when you start any command-line session. You can find the settings here:
HKLM\Software\Microsoft\Command Processor\AutoRun
HKCU\Software\Microsoft\Command Processor\AutoRun
|
Note
If you do not see an AutoRun setting in one or both keys, select the key; select File, New, String Value; type AutoRun; and press Enter.
Tip
The AutoRun Registry settings are handy if
you always run a particular command at the beginning of each
command-line session. If you run multiple commands to launch a session,
you can add those commands to either AutoRun setting. In that case, you must separate each command with the command separator string: &&. For example, to run the IPCONFIG and SET utilities at the start of each command-line session, change the value of an AutoRun setting to the following:
/A | Converts the output of internal commands to a pipe or file to the American National Standards Institute (ANSI) character set. |
/U | Converts the output of internal commands to a pipe or file to the Unicode character set. |
/T:bf | Sets the foreground and background colors of the Command Prompt window, where f is the foreground color and b is the background color. Both f and b are hexadecimal digits that specify the color as follows: |
| 0 | Black | 8 | Gray |
| 1 | Blue | 9 | Light Blue |
| 2 | Green | A | Light Green |
| 3 | Aqua | B | Light Aqua |
| 4 | Red | C | Light Red |
| 5 | Purple | D | Light Purple |
| 6 | Yellow | E | Light Yellow |
| 7 | White | F | Bright White |
Tip
You can also set the foreground and background colors during a command-line session by using the COLOR bf command, where b and f are hexadecimal digits specifying the colors you want. To revert to the default command prompt colors, run COLOR without the bf parameter.
/E:ON | Enables command extensions, which are extra features added to the following commands. (At the command line, type the command name followed by a space and /? to see the extensions.) |
| ASSOC | IF |
| CALL | MD or MKDIR |
| CD or CHDIR | POPD |
| COLOR | PROMPT |
| DEL or ERASE | PUSHD |
| ENDLOCAL | SET |
| FOR | SETLOCAL |
| FTYPE | SHIFT |
| GOTO | START |
/E:OFF | Disables command extensions. |
/F:ON | Turns
on file and directory name completion, which enables you to press
special key combinations to scroll through a list of files or
subdirectories in the current directory that match the characters you’ve
already typed. For example, suppose that the current directory contains
files named budget2009.doc, budget2010.doc, and budget2011.doc. If you type start budget in a command-line session started with /F:ON,
pressing Ctrl+F tells Windows Home Server to display the first file (or
subfolder) in the current folder with a name that starts with budget. Pressing Ctrl+F again displays the next file with a name that starts with budget, and so on. You can do the same thing with just subfolder names by pressing Ctrl+D instead. |
Tip
You don’t need to start the command prompt with the /F:ON switch to use file and directory name completion. The command prompt offers a similar feature called AutoComplete
that’s turned on by default. At the prompt, type the first letter or
two of a file or subfolder name, and then press the Tab key to see the
first object that matches your text in the current folder. Keep pressing
Tab to see other matching objects. If, for some reason, you prefer to
turn off AutoComplete, pull down the Command Prompt window’s control
menu (right-click the title bar), select Defaults, and then deactivate
the AutoComplete check box in the Options tab.
/F:OFF | Turns off file and directory name completion. |
/V:ON | Enables delayed environment variable expansion using ! as the delimiter: !var!, where var
is an environment variable. This is useful for batch files in which you
want to delay the expansion of an environment variable. Normally,
Windows Home Server expands all environment variables to their current
values when it reads the contents of a batch file. With delayed
expansion enabled, Windows Home Server doesn’t expand a particular
environment variable within a batch file until it executes the statement
containing that variable. |
/V:OFF | Disables delayed environment expansion. |
/S | Strips out the first and last quotation marks from command, provided the first quotation mark is the first character in command. |
/C | Executes the command and then terminates. |
/K | Executes the command and remains running. |
command | Specifies the command to run. |
Opening a Folder in a Command Prompt Session
When you’re working in Windows Explorer, you might
find that you need to do some work at the command prompt. For example,
the current folder might contain multiple files that need to be
renamed—a task that’s most easily done within a command-line session.
Selecting Start, Command Prompt starts the session in the %USERPROFILE% folder, so you have to use one or more CD commands to get to the folder you want to work in.
An easier way is to create a new action for the
Folder file type that launches the command prompt and automatically
displays the current Windows Explorer folder. To do this, follow these
steps:
1. | Select Start, Run (or press Windows Logo+R), type regedit, and then click OK to open the Registry Editor.
|
2. | Navigate to the following key:
|
3. | Select Edit, New, Key. Type Open with Command Prompt, and press Enter.
|
4. | Make sure that the key you created in step 3 is selected, and then select Edit, New, Key. Type command, and press Enter.
|
5. | With the new command key selected, double-click the Default value to open the Edit String dialog box.
|
6. | Type the following:
Note
In the command string, cd represents the command prompt’s internal CD (change directory) command, which changes the prompt to another folder. The %L placeholder represents the full pathname of the current folder.
|
7. | Click OK.
|
Figure 1 displays two windows. The top window is the Registry Editor showing the new Open with Command Prompt action added to the HKCR\Folder\shell key; in the bottom window, I right-clicked a folder. Notice how the new action appears in the shortcut menu.