Sub topic 1
Command Prompt basics: elevation, help, and syntax
Prerequisites
This chapter assumes you can do the following:
- Use the Windows desktop and File Explorer.
- Tell files, folders, drives, and partitions apart.
- Explain the difference between an administrator account and a standard user account.
You don't need earlier chapters. Every later command-line chapter builds on the habits here.
What Command Prompt is
Command Prompt (cmd.exe) is a text interpreter. You type a command and press Enter, and Windows runs it and prints the result. Some commands are built into cmd.exe, such as cd and dir. Others are separate programs, such as ipconfig.exe and chkdsk.exe. Both kinds are typed the same way.
The A+ Core 2 exam tests whether you can pick the right command for a symptom and run it with the right rights. PowerShell is a separate shell that can also run most of these commands. The exam focuses on classic Command Prompt syntax, so this tutorial does too.
Opening Command Prompt
You can open it in several ways:
- Press Win+R, type
cmd, and press Enter. - Search for "Command Prompt" in the Start menu.
- Right-click Start and choose Terminal or Windows Terminal, depending on the Windows version.
A normal launch gives you a standard-rights session. In that session the prompt starts in your user profile folder, for example C:\Users\Dana>.
Elevation
Elevation means running a process with full administrator rights. Windows uses User Account Control (UAC) to separate the two levels. Even if your account is an administrator, a normal program runs with a limited token until you approve elevation.
To open an elevated Command Prompt:
- Search for "Command Prompt" in the Start menu.
- Right-click the result and choose Run as administrator. You can also press Ctrl+Shift+Enter instead of Enter.
- Approve the UAC prompt. A standard user must enter an administrator's credentials.
You can confirm the result in two places:
- The title bar reads Administrator: Command Prompt.
- The starting path is
C:\Windows\System32>.
Commands that change the system usually need elevation. Examples include sfc /scannow, chkdsk /f, diskpart, gpupdate /force, and ipconfig /release. Read-only commands such as dir, ping, and hostname usually work without it.
Elevation applies to the whole window. If a command fails with "Access is denied" or "The requested operation requires elevation," you can't fix it from inside the same window. Close it and reopen it as administrator.
Reading help with /?
Most commands print their own help when you add /?:
ipconfig /?
robocopy /?
net use /?Two related commands are useful:
help
help dirhelp alone lists the built-in commands that cmd.exe documents. help dir shows the help for one of them. Help text can be longer than the window, so pipe it to more to page through it. Press Space for the next page and Q to quit.
robocopy /? | moreSome commands also use -? or --help, but /? is the standard form for classic Windows commands.
Reading syntax lines
Help output starts with a syntax line. Learn these conventions and you can read the help for any command:
| Notation | Meaning | Column |
|---|---|---|
| `[ ]` | The item is optional. | |
| `\ | ` between items | Choose one of the items. |
| `<value>` or italic text | A placeholder you replace with your own value. | |
| `/switch` | A switch (also called an option or parameter) that changes the behavior. |
A command line is built from three parts: the command name, its switches, and its arguments. In ping -n 4 example.com, ping is the command, -n 4 is a switch with a value, and example.com is the target. Some commands accept / switches, some accept - switches, and a few accept both. ping takes -n. shutdown takes /r. Check the help when unsure.
Rules that cause common errors
- Quote paths that contain spaces.
cd C:\Program Filesfails.cd "C:\Program Files"works. - Switches are not case sensitive.
/Fand/fare the same in most Windows commands. - Paths are not case sensitive on a default Windows file system.
- Wildcards
*(any characters) and?(one character) match file names, for exampledir *.log. - Chain commands with
&(run the second regardless) or&&(run the second only if the first succeeds). - Redirect output with
>(overwrite a file) or>>(append). For example,ipconfig /all > C:\Temp\net.txtsaves the output so you can attach it to a ticket. - "is not recognized as an internal or external command" means a typo, or a program that isn't in the folders listed in the
PATHvariable.
A few shortcuts save time:
- Tab completes file and folder names.
- The Up arrow recalls earlier commands, and F7 shows a history list.
- Ctrl+C stops a running command.
clsclears the screen.exitcloses the window.
Worked example
You suspect corrupted system files. First check whether the window is elevated, then read the help, then run the command:
whoami /groups | findstr /i "S-1-16-12288"
sfc /?
sfc /scannowwhoami /groups lists your group memberships. The ID S-1-16-12288 is the High Mandatory Level group. It appears only in an elevated session. If findstr prints nothing, the window is not elevated, so reopen it as administrator before running sfc /scannow.
Exercise
You run chkdsk C: /f in a Command Prompt you opened from the Start menu and get "Access is denied." What is the cause, and what do you do?
Show answer
The window is not elevated, and chkdsk /f needs administrator rights. Close it, reopen Command Prompt with Run as administrator (or Ctrl+Shift+Enter from search), approve the UAC prompt, confirm the title bar says Administrator: Command Prompt, and run the command again.
Exercise
cd C:\Program Files\Common Files returns "The system cannot find the path specified" even though the folder exists. How do you fix it?
Show answer
The path contains spaces, so cmd treats it as separate arguments. Put it in quotes: cd "C:\Program Files\Common Files".