Executing programs and internal commands
The difference between executables and built-in commands is that executables can also be started without cmd.exe
while the built-in commands require a running cmd.exe
to interpret and run them.
If cmd.exe
is run interactively, cmd.exe
lets the user enter a line of text. As soon as the user hits enter, cmd.exe
tries to execute what the user has entered. The first word of the entered line is the name of the executable or command to be executed, the remaining words are considered parameters to the command.
The command or executable might produce text (which it writes to
stdout). If this is the case,
cmd.exe
reads stdout an prints it back in the console.
For example,
echo
is a built-in command that simply prints the passed parameters:
C:\> echo Hello world
ping.exe
, on the other hand, is an executable. Like built-in commands, executables are identified by their first word. In the following execution of
ping
, the word
localhost
is passed as a parameter to
ping
:
C:\> ping localhost
Pinging pc3.tq84 [::1] with 32 bytes of data:
Reply from ::1: time<1ms
…
Note: the name of the executable is
PING.EXE
, not
ping
. So, why is it that
cmd.exe
still is able to find the «correct» executable?
Answer: it is possible because
cmd.exe
consults the values of the
PATHEXT
environment variable. It consists of a list of suffixes, separated by semicolons, that are added to the (supposed) name of the executable if
cmd.exe
is not able to locate the the executable by the given name at first.
Another suffix that is present in
PATHEXT
by default is
.msc
. Thus, the
device manager (whose complete name is
devmgmt.msc
) can be opened like so:
C:\> devmgmt
At this point, it should be noted that
cmd.exe
is able to locate the directories where with the
.exe
or
.msc
through the value of the
environment variable PATH
. This value consists of a set of directories, separated by semicolons. When
cmd.exe
tries to located an executable, it tries to search them in these specified directories.
A convenient way to determine what
cmd.exe
would execute is
where.exe
(which itself is an executable). For example, if called with the argument
services
, it (typically) responds with two files:
C:\> where services
C:\Windows\System32\services.exe
C:\Windows\System32\services.msc
This is because PATHEXT
contains both suffixes, .exe
and .msc
, and reports both. However, if executed on the command line, only the first one that is found will actually be executed.
If the first word of the entered text is neither a built-in command nor an executable, cmd.exe
responds like so:
C:\> doesNotExist foo bar
'doesNotExist' is not recognized as an internal or external command,
operable program or batch file.
Keyboard shortcuts
Selecting text linewise
Text can be selected linewise with shift
+ up/down
.
Mark mode
In mark mode, one can navigate through the text with the arrow keys and select portions of the text with the shift
key and then copy/paste it.
In mark mode, unfortunately, ctrl+shift+right
does not jump to the end of a word.
When a selection is started by pressing ctrl+shift+alt
, the selection is in line wrapping mode.
If the selection is started by pressing ctrl+shift
, the selection is in block mode.
TODO
The
actual console program behind cmd.exe is
conhost.exe
.
ANSICON promises ANSI escape sequences for Windows console programs, similarly as ANSI.SYS did for MS-DOS.
Starting the management console
C:\> mmc
Starting the device manager:
C:\> devmgmt.msc
C:\> mmc devmgmt.msc
C:\> UserAccountControlSettings
More msc:
azman.msc | Authorization manager |
certlm.msc | Certificates (local computer) |
certmgr.msc | Certificates (current user |
comexp.msc | Component services |
compmgmt.msc | Computer management |
devmgmt.msc | Device manager |
DevModeRunAsUserConfig.msc | Start menu and taskbar |
diskmgmt.msc | Disk management (partition, drive paths) |
eventvwr.msc | Event viewer |
fsmgmt.msc | Shared folders |
gpedit.msc | Local group policy editor |
lusrmgr.msc | Local users and groups |
perfmon.msc | Performance monitor |
printmanagement.msc | |
rsop.msc | Resultant set of policy |
secpol.msc | allows to configure the elevation prompt (Local Security Policy). |
services.msc | Services |
taskschd.msc | Task scheduler, compare with schtasks.exe |
tpm.msc | Trusted platform module (TPM) |
WF.msc | Windows defender firewall |
WmiMgmt.msc | Windows management instrumentation (WMI) |