Cmd.exe
Start a new CMD shell and (optionally) run a command/executable program.
Syntax
CMD [charset] [options] CMD [charset] [options] [/C Command] CMD [charset] [options] [/K Command]
Options
/C Run Command and then terminate /K Run Command and then return to the CMD prompt. This is useful for testing, to examine variables Command : The command, program or batch script to be run. This can even be several commands separated with '&' (the whole should also be surrounded by "quotes") /T:fg Sets the foreground/background colours /X Enable extensions to CMD.EXE /Y Disable extensions to CMD.EXE /A Output ANSI characters /U Output UNICODE characters (UCS-2 le) These options will affect piping or redirecting to a file. Most common text files are ANSI, use these switches when you need to convert the character set. /D Ignore registry AutoRun commands HKLM | HKCU \Software\Microsoft\Command Processor\AutoRun /E:ON Enable Command Extensions (default) /E:OFF Disable Command Extensions /F:ON Enable auto-completion of pathnames entered at the CMD prompt /F:OFF Disable auto-completion of pathnames entered at the CMD prompt (default) At the command prompt Ctrl-D gives folder name completion and Ctrl-F gives File and folder name completion. These key-strokes will display the first matching path. Thereafter, repeated pressing of the same control key will cycle through the list of matching paths. Pressing SHIFT with the control key will move through the list backwards. /Q Turn echo off /S Strip quote characters from the command_line /V:ON Enable delayed environment variable expansion this allows a FOR loop to specify !variable! instead of %variable% expanding the variable at execution time instead of at input time. /V:OFF Disable delayed environment expansion. Delayed Environment expansion can also be set with SETLOCAL
If /C or /K is specified, then the remainder of the command line is processed as an immediate command in the new shell. Multiple commands separated by the command separator '&' or '&&' are accepted if surrounded by quotes.
For more details on working in the CMD shell: QuickEdit, handing quotes etc, see the CMD Syntax page. ErrorLevel
CMD /C will return an errorlevel, for example CMD /c dir Z: where the drive Z: does not exist, will return %errorlevel% = 1 to the calling CMD shell. Command Extensions
Much of the functionality of CMD.exe can be disabled - this will affect all the internal commands, Command Extensions are enabled by default. This can be changed by setting a value in the registry: HKCU\Software\Microsoft\Command Processor\EnableExtensions Command Extensions can also be turned on or off by running CMD /e:on or CMD /e:off or run SETLOCAL EnableExtensions (SetLocal will take precedence)
The /knetdiag switches are undocumented and work in Windows XP only, they list and may fix several networking issues.
/knetdiag /debug /knetdiag /fix
Examples:
Run a program and pass a Filename parameter:
CMD /c write.exe c:\docs\sample.txt
Run a program and pass a Long Filename:
CMD /c write.exe "c:\sample documents\sample.txt"
Spaces in Program Path:
CMD /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""
Spaces in Program Path + parameters:
CMD /c ""c:\Program Files\demo.cmd"" Parameter1 Param2
Spaces in Program Path + parameters with spaces:
CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""
Launch Demo1 and then Launch Demo2:
CMD /c ""c:\Program Files\demo1.cmd" & "c:\Program Files\demo2.cmd""