1. What is a DOS prompt?
Technically, there's no such thing as a "DOS prompt", as DOS is an operating system. DOS came with a command interpreter called command.com, which presents the legendary "C: prompt" to the user. This is referred to as a command-line interface (CLI).
The Windows NT platform (Windows NT 4.0 and later, including Windows 2000, XP, and Server 2003) provides a CLI program called cmd.exe, which is a Win32 console program, not a DOS program. The operating system does come with a program called command.com, but it's provided for compatibility purposes.
2. What is a Win32 console program?
A Win32 console program is a 32-bit windows program that runs in a console (e.g. text-based) window, rather than as a GUI program.
3. Why don't the up and down arrows work?
You are most likely running command.com rather than cmd.exe. To get to a command window, run cmd.exe, not command.com.
4. How do I do X from a DOS prompt?
I think you mean to ask "how do I do X from a cmd prompt?" On the Windows NT platform (Windows NT/2000/XP/Vista/etc.), there is no DOS.
5. How do I get user input in a batch file?
There are 3 basic answers to this question. The first one is my favorite because 1) I wrote the programs and 2) they provide the greatest amount of flexibility.
- Use EditVar or Choose to get keystroke or string input. Choose is like Choice, except better, and EditVar lets you read a string into an environment variable. Note that I also compiled true DOS versions, so the DOS versions work from DOS (e.g. a boot floppy).
- Use Choice from the Resource Kit. It lets you read a keystroke, and the result is returned to the batch file as an ERRORLEVEL.
- Use Set /P to read a string of input directly into an environment variable. This only works in Cmd.exe in Windows 2000 and later.
Another nice feature of EditVar is that it supports password-style input, displaying asterisks on the input line.
6. Why don't my commands work?
When you type the name of an executable program in a command prompt window, cmd.exe processes the command name as follows:
- If the command includes a path, cmd.exe checks if the specified executable exists in the specified path. If it does, then cmd.exe executes it; otherwise, it reports an error.
- If the command doesn't specify a path, the cmd.exe searches the current directory for an executable matching the command name. If the executable exists in the current directory, cmd.exe runs the executable. If the executable was not found in the current directory, it skips to the next step.
- If the executable was not found in the current directory, cmd.exe searches each directory in the Path environment variable, in order, for an executable matching the command name you typed. If the executable exists in any directory specified in the path, cmd.exe executes it; otherwise, it reports an error.
PowerShell also works like the above, except that it does not search the current directory for executables.
If commands don't work, then, the first thing you should check is the contents of your Path variable. At a bare minimum, your Path should start with the following:
Of course, %SystemRoot% refers to the system installation folder on your system (e.g. "C:\WINNT").
In some cases, the actual contents of the environment variable is correct, but the registry data type is incorrect. The system registry environment variable type should be REG_EXPAND_SZ, not REG_SZ.
I have written a small program called FixPath that attempts to fix these problems. Give it a try and see if it works correctly for you.
To check your registry setting manually, run regedt32 and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment. Examine the registry data type of the Path entry. If it is not REG_EXPAND_SZ, then you need to perform the following steps:
- Open the Path entry so that it is an editable string.
- Select the entire string, and press Ctrl+C to copy it to the clipboard.
- Cancel editing of the Path entry.
- Open notepad and paste the string, to make sure it copied to the clipboard correctly.
- Delete the Path entry.
- Create a new value called Path and make sure that you select REG_EXPAND_SZ as the data type.
- For the contents, press Ctrl+V to paste the contents of the clipboard.
- Click OK to save the contents of the registry value.
The cause of this problem is probably an installation program that doesn't correctly read and re-write the registry value with the correct data type.
7. Why can't I do things when there are spaces in a file or directory name?
Spaces indicate separate parameters to the command interpreter. To indicate that a parameter contains spaces, enclose it in quotation marks. The quotation marks are not passed to the command as part of the parameter. (At least one exception to this rule is cmd's cd command, which lets you skip the quotes if command extensions are enabled.)
For example, suppose you type the following command:
copy C:\Program Files\test1.txt D:\Program Files\test2.txt
This command has four parameters: "C:\Program", "Files\test1.txt", "D:\Program", and "Files\test2.txt". This is probably not what you intended.
To get around this issue, you need to enclose the individual parameters in quotation marks; e.g.
copy "C:\Program Files\test1.txt" "D:\Program Files\test2.txt"
The quotation marks indicate the separate parameters, which the command interpreter program will then parse correctly.
8. How do I reset a computer's Administrator account password from the command line?
Use the Reset-LocalAdminPassword.ps1 PowerShell script in my Windows IT Pro article Resetting the Local Administrator Password on Computers.
9. How do I boot into DOS mode in Windows 2000?
This is not possible, as there is no "DOS mode" to boot into.
Incidentally, one frequently given answer to this question is "Use a DOS bootable floppy." This merely boots the computer from a floppy disk, rather than the hard drive, and does not constitute a "DOS mode."