For the most part, the features of the command line are the same in Vista/7 as they are in Windows XP but there are some differences. Here are some tips that apply only to Windows Vista and/or Windows 7.
Run as administrator in Vista/7
The Windows Vista/7 operating system has a security feature called User Account Control that limits the privileges of users by default. Since the command line is usually involved with administrative tasks, you'll often want to run as an administrator. This can be done each time by right-clicking the icon for the command prompt and choosing "Run as administrator " from the context menu . A more convenient way is to set the command prompt to run with administrator privileges by default. Right-click the command prompt shortcut icon and choose "Properties" from the context menu. Click the "Advanced" button and put a check by "Run as administrator". Click "OK". Note that you will still get the UAC message when you open the command prompt.
Another way to run the command prompt as administrator is to enter "cmd" in Start Search and then use the keyboard combination Ctrl+Shift+ Enter.
"Open Command Window Here" in Vista/7
It is now easy to open a command prompt referenced to a folder of your choice in Vista/7. If the Shift key is held down while right-clicking a folder, the context menu will contain an entry, "Open Command Window Here". Selecting this entry will open a command prompt with the chosen folder as the reference point for commands.
Open command window with administrator privileges anywhere
The "Run as administrator" option mentioned above always opens with \Windows\System 32\ as the working directory. To open a command console with administrator privileges in any directory of choice, you can add a command to the right-click context menu. The INF file to make the appropriate Registry edit can be downloaded here. It is from the PowerToy utility described at this link.
Send command output to the Windows clipboard with clip.exe
Vista/7 comes with a command-line utility clip.exe that can be used to redirect or pipe the output of another command to the Windows clipboard. The command uses a "pipe" and has the form:
somecommand | clipFor example, to send a directory listing to the clipboard, the command is:
dir | clip
Place the contents of a text file into the Windows clipboard with clip.exe
The utility clip.exe can also be used to read a text file and place its contents in the Windows clipboard. The command has the form:
clip < somefile.txt
Clear the Windows clipboard with clip.exe
To clear the contents of the Windows clip board, use a "pipe" :
echo off | clip
The batch file command called "choice" is back in Vista/7
Oldtimers will remember that DOS had a command for batch files called "choice" that allowed for some limited user interaction. The command was then removed from 32-bit command shells because the "set /p" option gave equivalent or better functionality. However, "choice" is back in Vista/7 in a new form. Enter "choice /?" in a Vista/7 command prompt for details about its features.
Use the "choice" command to make a Vista/7 batch file wait
One useful application of the "choice" command is to make a batch file pause for a specified period of time. The statement has the form:
choice /T n /D y > nul The switch "/T n" specifies a wait period of n seconds. The switch "/D y" creates a default choice of "yes". To suppress the unwanted text output of the command, it is redirected to the null device (nul).
Another new command in in Vista/7 is "timeout". It will cause the command processor to wait for a specified number of seconds or until a key is pressed. The format is
timeout /T n where n is the number of seconds to wait. To make the command ignore any key presses, the switch /nobreak can be added:
timeout /T n /nobreak Because the command gives output listing the time remaining, it may be necessary to use a redirect to nul.
timeout /T n > nul
Switch added to "Dir" to enable viewing Alternate Data Streams
NTFS files can have added information in "streams" or "forks". These added items are normally hidden from access by most Windows functions such as Explorer. In Vista/7 a switch /R has been added to the "dir" command that allows alternate data streams to be listed.
Enable the built-in master administrator account on the log-in screen
Vista/7 contain a master administrator account but it is not normally visible on the log-in screen. To enable it, open a command window with administrator privileges and use the command
net user administrator /active:yes (Make sure that you assign a password to the account.) To remove the account from the log-in screen, use the command
net user administrator /active:no
Increase the file system memory cache with fsutil
If you tend to open and close a lot of files, you may be able to increase performance by creating a larger value for a special cache setting with the file system utility command
fsutil behavior set memoryusage 2According to Microsoft, this increases something called the "paged pool" memory. Do not use if you are already consuming large amounts of system memory with other activities. If performance after the change is unsatisfactory, undo it with the command
fsutil behavior set memoryusage 1These commands require administrator privileges. The commands change a Registry setting and take effect after a reboot.
Vista/7 protects many system files for security reasons and even an administrator may not allowed to access certain of them. If you are denied access to a file while in an administrator account, you can use the command line tool "takeown.exe" to reassign ownership. You will need to run the command from a command prompt with administrator privileges. The syntax is
takeown /f some_file [/a] [/r]The specified filename can contain wildcards. You can also specify a folder. The optional switch "/a" transfers ownership to the administrators group. If omitted, the default is to transfer ownership to the present user account. The switch "/r" recurses subdirectories. Although this command assigns ownership, it does not give control rights. Thus if you wish to modify a system file (often not a good idea) you will probably have also to apply the "icacls" command discussed next.
(Icacls.exe supersedes the "cacls" command of Windows XP. The older command is still available, however.) This command has a rather complex set of options. They can be displayed by entering "icacls /?" in a command prompt. One example is the command to grant full access rights to an account named user:
icacls file_name /grant user:F
Using drag and drop- no in Vista, yes in Windows 7
The useful capability to drag commands and drop them into a command prompt that was present in past versions of Windows does not work in Vista. However, it has been restored in Windows 7.
Information about Vssadmin has been expanded to a full page that can be found at this link.