IT tutorials
 
Windows
 

Using Windows Home Server’s Command-Line Tools : Working at the Command Line

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
4/30/2013 3:36:35 AM
When you have your command-line session up and running, you can run commands and programs, create and launch batch files, perform file maintenance, and so on. If you haven’t used the command prompt since the days of DOS, you’ll find that the Windows Home Server command prompt offers a few extra command-line goodies. The next few sections highlight some of the more useful ones.

Caution

When you’re working in the command prompt, be warned that any files you delete aren’t sent to the Recycle Bin but are purged from your system.


Running Commands

Although many of the Windows Home Server accessories provide more powerful and easier-to-use replacements for nearly all commands, a few commands still have no Windows Home Server peer. These include the REN command, as well as the many Command Prompt-specific commands, such as CLS, DOSKEY, and PROMPT.

Note

Command-line commands that exist as separate executable files—such as CHKDSK, DEFRAG, and XCOPY—are called external commands; all other command-line commands—such as DIR, CD, and CLS—are part of the CMD shell and are known as internal commands.


The way you run a command depends on whether it’s an internal or external command and on what you want Windows Home Server to do after the command is finished. For an internal command, you have two choices: You can either enter the command in the command prompt, or you can include it as a parameter with CMD. As you saw earlier, you can run internal commands with CMD by specifying either the /C switch or the /K switch. If you use the /C switch, the command executes, and then the command-line session shuts down. This is fine if you’re running a command for which you don’t need to see the results. For example, if you want to redirect the contents of drive C:’s root folder in the text file root.txt, entering the following command in the Run dialog box (for example) will do the job:

cmd.exe /c dir c:\ > root.txt

On the other hand, you might want to examine the output of a command before the Command Prompt window closes. In that case, you need to use the /K switch. The following command runs DIR on drive C:’s root folder and then drops you off in the command prompt:

cmd.exe /k dir c:\

For an external command, you have three choices: Enter the command in the command prompt, enter the command by itself from within Windows Home Server, or include it as a parameter with CMD.

Entering a command by itself from within Windows Home Server means launching the command’s file in Explorer, entering the command in the Start menu or Run dialog box, or creating a shortcut for the command. For the latter two methods, you can embellish the command by adding parameters and switches. The problem with this method is that Windows Home Server automatically closes the Command Prompt window when the command completes. To change this behavior, follow these steps:

Note

When you use the command prompt or the Run dialog box to start an external command prompt command, you don’t need to use the command’s full pathname. For example, the full pathname for mem.exe is %SystemRoot%\System32\mem.exe, but to run this command, you need to enter only mem. The reason is that the %SystemRoot%\System32 subfolder is part of the PATH statement for each command-line session.


1.
Find the command’s executable file in the %SystemRoot%\System32 folder.

2.
Right-click the executable file, and then click Properties to display the command’s properties sheet.

3.
Display the Program tab. (Note that this tab doesn’t appear for all commands.)

4.
Deactivate the Close on Exit check box.

5.
Click OK.

Working with Long Filenames

If you want to use long filenames in a command, you need to be careful. If the long filename contains a space or any other character that’s illegal in an 8.3 filename, you need to surround the long name with quotation marks. For example, if you run the following command

copy Fiscal Year 2011.doc Fiscal Year 2012.doc

Windows Home Server tells you this:

The syntax of the command is incorrect:

Instead, you need to enter this command as follows:

copy "Fiscal Year 2011.doc" "Fiscal Year 2012.doc"

Long filenames are, of course, long, so they tend to be a pain to type in the command prompt. Fortunately, Windows Home Server offers a few methods for knocking long names down to size:

  • In Explorer, drag a folder or file and drop it inside the Command Prompt window. Windows Home Server pastes the full pathname of the folder or file to the end of the prompt.

  • In Windows Explorer, navigate to the folder you want to work with, and then select and copy the folder path in the address bar. Return to the Command Prompt window, type the command up to the point where you want the path to appear, right-click the title bar, and then select Edit, Paste.

  • If you’re trying to run a program that resides in a folder with a long name, add the folder to the PATH. This technique enables you to run programs from the folder without having to specify the full pathname.

Tip

To edit the PATH environment variable, you have two choices. At the command line, enter the following command (where folder is the path of the folder you want to add to the PATH variable):

path %path%;folder

Alternatively, select Start, Control Panel, System (or select Start, right-click Computer, and then click Properties), and then click Advanced System Settings to open the System Properties dialog box. In the Advanced tab, click Environment Variables. In the System Variables list, click Path, click Edit, and then append the folder to the end of the Variable Value string. Be sure to separate each folder path with a semicolon (;).


Use the SUBST command to substitute a virtual drive letter for a long pathname. For example, the following command substitutes drive S: for the Start menu’s System Tools folder:

subst s: "%AllUsersProfile%\Microsoft\Windows\Start Menu\Programs\Accessories\System Tools"

					  

Changing Folders Faster

I mentioned earlier that you use the CD command to change to a different folder on the current drive. However, the command prompt has a few short forms you can use to save time.

You might know that both the command prompt and Windows Home Server use the dot symbol (.) to represent the current folder, and the double-dot symbol (..) to represent its parent folder. You can combine the CD command and the dot notation to jump immediately to a folder’s parent folder, or even higher.

To make this more concrete, suppose that the current folder is C:\Animal\Mammal\Dolphin. Table 1 demonstrates the techniques you can use to navigate to this folder’s parent, grandparent (two levels up), and great-grandparent (three levels up) folders.

Table 1. Combining the CD Command with Dot Notation
Current FolderCommandNew Folder
C:\Animal\Mammal\DolphinCd..C:\Animal\Mammal
C:\Animal\Mammal\DolphinCd..\..C:\Animal
C:\Animal\Mammal\DolphinCd..\..\..C:\
C:\Animal\Mammal\DolphinCd..\BaboonC:\Animal\Mammal\Baboon

Tip

If you want to return to the root folder of any drive, type cd\ and press Enter.


Taking Advantage of DOSKEY

Windows Home Server loads the DOSKEY utility by default when you start any command-line session. This useful little program brings a number of advantages to your command-line work:

  • You can recall previously entered commands with just a keystroke or two.

  • You can enter multiple commands on a single line.

  • You can edit commands instead of retyping them.

The next few sections take you through the specifics.

Recalling Command Lines

The simplest DOSKEY feature is command recall. DOSKEY maintains a command history buffer that keeps a list of the commands you enter. To scroll through your previously entered commands in reverse order, press the up-arrow key; when you’ve done that at least once, you can change direction and run through the commands in the order you entered them by pressing the down-arrow key. To rerun a command, use the arrow keys to find it, and then press Enter.

Tip

If you don’t want to enter commands from the history buffer, press Esc to get a clean command line.


Table 2 lists all the command-recall keys you can use.

Table 2. DOSKEY Command-Recall Keys
PressTo
Up arrowRecall the previous command in the buffer.
Down arrowRecall the next command in the buffer.
Page UpRecall the oldest command in the buffer.
Page DownRecall the newest command in the buffer.
F7Display the entire command buffer.
Alt+F7Delete all commands from the buffer.
F8Have DOSKEY recall a command that begins with the letter or letters you’ve typed on the command line.
F9Have DOSKEY prompt you for a command list number. (You can see the numbers with the F7 key.) Type the number and press Enter to recall the command.

Tip

The command history buffer holds 50 commands by default. If you need a larger buffer, run DOSKEY with the /LISTSIZE=buffers switch, where buffers is the number of commands you want to store. You also need to include the /REINSTALL switch to install a new copy of DOSKEY, which puts the new history buffer setting into effect. For example, to change the buffer size to 100, enter the following command:

doskey /listsize=100 /reinstall


Entering Multiple Commands on a Single Line

DOSKEY enables you to run multiple commands on a single line. To do this, insert the characters && between commands. For example, a common task is to change to a different drive and then run a directory listing. Normally, you’d do this with two separate commands:

e:
dir

With DOSKEY, however, you can do it on one line, like so:

e:&&dir

Tip

You can enter as many commands as you like on a single line, but just remember that the total length of the line can’t be more than 8,191 characters, which should be plenty!


Editing Command Lines

Rather than simply rerunning a previously typed command, you might need to run the command again with slightly different switches or parameters. Rather than retyping the whole thing, DOSKEY enables you to edit any recalled command line. You use various keys to move the cursor to the offending letters and replace them. Table 3 summarizes DOSKEY’s command-line editing keys.

Table 3. DOSKEY Command-Line Editing Keys
PressTo
Left arrowMove the cursor one character to the left.
Right arrowMove the cursor one character to the right.
Ctrl+left arrowMove the cursor one word to the left.
Ctrl+right arrowMove the cursor one word to the right.
HomeMove the cursor to the beginning of the line.
EndMove the cursor to the end of the line.
DeleteDelete the character over the cursor.
BackspaceDelete the character to the left of the cursor.
Ctrl+HomeDelete from the cursor to the beginning of the line.
Ctrl+EndDelete from the cursor to the end of the line.
InsertToggle DOSKEY between Insert mode (your typing is inserted between existing letters on the command line) and Overstrike mode (your typing replaces existing letters on the command line).

Redirecting Command Output and Input

Windows Home Server is always directing things here and there. This generally falls into two categories:

  • Directing data into its commands from a device called standard input

  • Directing data out of its commands to a device called standard output

A device called CON (console) normally handles standard input and standard output, which is your keyboard and monitor. Windows Home Server assumes that all command input comes from the keyboard and that all command output (such as a DIR listing or a system message) goes to the screen. Redirection is just a way of specifying different input and output devices.

Redirecting Command Output

To send command output to somewhere other than the screen, you use the output redirection operator (>). One of the most common uses for output redirection is to capture the results of a command in a text file. For example, you might want to use the report produced by the SYSTEMINFO command as part of a word-processing document. You could use the following command to first capture the report as the file systeminfo.csv:

systeminfo /fo csv > c:\systeminfo.csv

When you run this command, the usual SYSTEMINFO data doesn’t appear onscreen. That’s because you directed it away from the screen and into the systeminfo.csv file.

You can use this technique to capture DIR listings, CHKDSK reports, and more. One caveat: If the file you specify as the output destination already exists, Windows Home Server overwrites it without warning. To avoid this, you can use the double output redirection symbol (>>). This tells Windows Home Server to append the output to the end of the file if the file exists. For example, suppose you used the following command to output the results of the CHKDSK C: command to chkdsk.txt:

chkdsk c: > c:\chkdsk.txt

If you then want to append the results of the CHKDSK D: command to chkdsk.txt, you’d enter the following command:

chkdsk d: >> c:\chkdsk.txt

You can also redirect output to different devices. Table 4 lists the various devices that Windows Home Server installs each time you start your system.

Table 4. Devices Installed by Windows Home Server When You Start Your System
Device NameDevice
AUXAuxiliary device (usually COM1)
CLOCK$Real-time clock
COMnSerial port (COM1, COM2, COM3, or COM4)
CONConsole (keyboard and screen)
LPTnParallel port (LPT1, LPT2, or LPT3)
NULNUL device (nothing)
PRNPrinter (usually LPT1)

For example, you can send a DIR listing to the printer with the following command. (Of course, you need to be sure that your printer is on before doing this. Also note that this only works for a printer attached to a parallel port; it doesn’t work for USB printers.)

dir > prn

The NUL device usually throws people for a loop when they first see it. This device (affectionately known as the bit bucket) is, literally, nothing. Batch files normally use it to suppress the usual messages Windows Home Server displays when it completes a command. For example, Windows Home Server normally says 1 file(s) copied when you copy a file. However, the following command sends that message to NUL, so you wouldn’t see it onscreen:

copy somefile.doc \\server\users\paul\ > nul

Tip

Unfortunately, Windows Home Server gives you no way to redirect output to a USB port. However, there’s a workaround you can use if you’re trying to redirect output to a USB printer. Assuming that the printer is shared and that no other device is using the port LPT2, run the following command:

NET USE LPT2 \\server\printer

Here, replace server with the name of your Windows Home Server computer and printer with the share name of the USB printer. Now, when you redirect output to LPT2, Windows Home Server sends the output to the USB printer.


Redirecting Command Input

The input redirection operator (<) handles getting input to a Windows Home Server command from somewhere other than the keyboard. Input redirection is almost always used to send the contents of a text file to a Windows Home Server command. The most common example is the MORE command, which displays one screen of information at a time. If you have a large text file that scrolls off the screen when you use TYPE, the following command, which sends the contents of BIGFILE.TXT to the MORE command, solves the problem:

more < bigfile.txt

When you run this command, the first screen of text appears, and the following line shows up at the bottom of the screen:

– More –

Just press any key, and MORE displays the next screen. (Whatever you do, don’t mix up < and > when using MORE. The command more > bigfile.txt erases BIGFILE.TXT!) MORE is an example of a filter command. Filters process whatever text is sent through them. The other Windows Home Server filters are SORT and FIND, which I discuss in a moment.

Another handy use for input redirection is to send keystrokes to Windows Home Server commands. For example, create a text file called enter.txt that consists of a single press of the Enter key, and then try this command:

date < enter.txt

Windows Home Server displays the current date, and instead of waiting for you to either type in a new date or press Enter, it just reads enter.txt and uses its single carriage return as input. (For an even easier way to input the Enter key to a command, check out the next section.)

One common recipient of redirected input is the SORT command. SORT, as you might guess from its name, sorts the data sent to it and displays the results onscreen. So, for example, here’s how you would sort a file called JUMBLED.TXT:

sort < jumbled.txt

Instead of merely displaying the results of the sort onscreen, you can use > to redirect them to another file.

Tip

SORT normally starts with the first column and works across. To start with any other column, use the /+n switch, where n is the number of the column you want to use. To sort a file in reverse order (that is, a descending sort—Z to A, then 9 to 0—instead of an ascending sort—0 to 9, then A to Z), use the /R switch.


Piping Commands

Piping is a technique that combines both input and output redirection. Using the pipe operator (|), the output of one command is captured and sent as input to another command. For example, the SYSTEMINFO command displays about five screens of data, so you usually need to scroll back to see the data you’re looking for. However, you can pause the output by piping it to the MORE command:

systeminfo | more

The pipe operator captures the SYSTEMINFO output and sends it as input to MORE, which then displays the SYSTEMINFO results one screen at a time.

Note

Piping works by first redirecting the output of a command to a temporary file. It then takes this temporary file and redirects it as input to the second command. A command such as SYSTEMINFO | MORE is approximately equivalent to the following two commands:

SYSTEMINFO > tempfile
MORE < tempfile


I showed you in the preceding section how to use input redirection to send keystrokes to a Windows Home Server command. But if you have to send only a single key, piping offers a much nicer solution. The secret is to use the ECHO command to echo the character you need and then pipe it to the Windows Home Server command.

For example, if you use the command DEL *.*, Windows Home Server always asks whether you’re sure that you want to delete all the files in the current directory. This is a sensible precaution, but you can override it if you do things this way:

echo y | del *.*

Here, the y that would normally be echoed to the screen is sent to DEL instead, which interprets it as a response to its prompt. This is a handy technique for batch files in which you want to reduce or even eliminate user interaction.

Tip

You can even use this technique to send an Enter keypress to a command. The command ECHO. (that’s ECHO followed by a period) is equivalent to pressing Enter. So, for example, you could use the following command in a batch file to display the time without user input:

ECHO. | TIME
 
Others
 
- Using Windows Home Server’s Command-Line Tools : Getting to the Command Line
- Windows Vista : Desktop Searching with the Windows Search Engine
- Windows Vista : Metadata and the Windows Explorer Property System
- Windows 7 : Email and Newsgroups with Windows Live Mail - Creating and Sending New Mail
- Windows 7 : Email and Newsgroups with Windows Live Mail - Windows Live Mail Quick Tour
- Monitoring Windows Small Business Server 2011 : Configuring the Backup Service (part 2) - Windows Server Backup Using Native Tools
- Monitoring Windows Small Business Server 2011 : Configuring the Backup Service (part 1) - Windows Server Backup Using SBS Wizards
- Windows 8 : Settings and Customization - Modifying Startup Programs and Services
- Windows 8 : Settings and Customization - Windows Features
- Microsoft Windows Home Server 2011 : Restoring Network Backups
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us