Common DOS and Windows Commands

Common Windows Command Lines

Computer Management: compmgmt.msc
Control Panel: control
Device Manager: devmgmt.msc
DirectX Version: dxdiag
Disk Management: diskmgmt.msc
Drive Cleanup: cleanmgr
Event Viewer: eventvwr.msc
Group Policy Editor: gpedit.msc
Microsoft Management Console: mmc **

Performance Monitior Console: perfmon **
Registry Editor: regedit, or regedit32
Services: services.msc
System Configuration Utility: msconfig
System Information: msinfo32
System Properties: sysdm.cpl
Windows File Protection: sfc /scannow (Installs original files)
Windows Management Infrastructure: wmimgmt.msc

** (These items may be restricted by Group Policies - a registry tweak may be required to gain access)

DOS / Windows IP Command Lines
Display Connection Configuration: ipconfig /all
Display DNS Cache Info Configuration: ipconfig /displaydns
Clear DNS Cache: ipconfig /flushdns
Release All IP Address Connections: ipconfig /release
Renew All IP Address Connections: ipconfig /renew
Re-Register the DNS connections: ipconfig /registerdns
Change/Modify DHCP Class ID: ipconfig /setclassid
Network Connections: control netconnections
List or Map Network Drives: net use

Network Setup Wizard: netsetup.cpl
Ping (continuous): Ping <URL> -t (or use "/?" for switch list)
Test Connectivity: ping www.whatismyip.com
Trace IP address Route: tracert
Displays the TCP/IP protocol sessions: netstat
Display Local Route: route
Display Resolved MAC Addresses: arp
Display Name of Computer Currently on: hostname
Display DHCP Class Information: ipconfig /showclassid


Other Handy DOS Commands
List Running Processes: wmic process get description,executablepath
Print a List of Running Processes: wmic /output:c:\process.txt process get description,executablepath
Create a simple list of files in a directory, output to a text file: dir /b/s >dirtext.txt
Create a list of files in a directory, including sub-directories, sorted by directory, to a text file: dir /s /b /o:gn > Listing.txt

More Information >> - Command line syntax to stop services

Copy and Paste in an MS-DOS window (Two Options):

Option 1:Quick Edit Mode Disabled

  1. Right click on the Command Prompt window and choose Mark option
  2. Now select or highlight the text by pressing and holding down the Shift key and then move arrow keys
  3. When the desired text is selected, press Enter key and then text will be copied to the Clipboard
  4. Open any text editor such as Notepad and paste the text there by pressing Ctrl + V keys
Option 2: Quick Edit Mode Enabled
Here you can directly highlight the text in the Command Prompt by left clicking the mouse and then dragging it over the desired text.
  1. First enable Quick Edit Mode. To know how to do it click the link How to Enable Quick Edit Mode in Command Prompt?
  2. Now simply left click the mouse and drag it over the desired text to highlight it
  3. When the desired text is selected, press Enter key and then text will be copied to the Clipboard
  4. Open any text editor such as Notepad and paste the text there by pressing Ctrl + V keys
To paste text into an MS-DOS window, simply right click to paste clipboard text.

Problems...

If you're unable to highlight text in the window, right-click on the title bar and click Properties; in the Properties window, click the Options tab, and check the "QuickEdit Mode" and click the Ok button.

Windows will prompt you how you wish to apply the new changes. If you wish to always have this option available (recommended), select "Save properties for future windows with same title" and click Ok.

How to copy an entire directory tree WITHOUT the files

Use XCopy as follows: XCOPY C:\SOURCE E:\TARGET /T /E,
Where "C:\SOURCE" is the source directory, and "E:\TARGET" is the target directory.
Note: use quotes for any path that includes blanks, or long file names (e.g.: "C:\Directory sample"), also, leave off the final "\" in the path.
/T - Copy Directory and Subdirectories except files
/E - Includes the empty directories as well.
- - - - - - - - - - - - - - - - ---------
Example to copy the tree of a folder "SOURCE" described below :

C:\SAMPLE> including subfolders as follows:
C:\SAMPLE\SUB1>
C:\SAMPLE\SUB2>

At the DOS Command Prompt type the following command (as an example):
XCOPY C:\SAMPLE E:\SAMPLE /T /E >> Copies directories only from C: to E:, with no files.
- - - - - - - - - - - - - - - - ---------
To copy the SAMPLE folder on the same C drive with a new name then you can use:
XCOPY C:\SAMPLE C:\NEW_NAME /T /E
- - - - - - - - - - - - - - - - ---------
System Variable Names (e.g. %SYSTEMROOT%). From a command window (Start - Run - cmd) type "set" without the quote marks, to get a list of all the variables the system knows about (local).


DOS Command Line - Connect or Disconnect Network Drives
Use the Net Use command to map or disconnect a drive
You can use the net use command for batch files and scripts. To use the net use command to map or disconnect a drive:

To map a network drive:
  1. Click Start, and then click Run.
  2. In the Open box, type cmd.
  3. Type net use x: \\computer name\share name, where x: is the drive letter you want to assign to the shared resource.
To disconnect a mapped drive:
  1. Click Start, and then click Run.
  2. In the Open box, type cmd.
  3. Type net use x: /delete, where x: is the drive letter of the shared resource.

DOS Command Line Operators (or Batch File)
Operator Usage and Result (More Redirects)
&
Command A & Command B - execute command A, then execute command B. (no evaluation)
example: dir c:\ & echo All done!
|
Command A | command B - execute command A, and redirect all Command A's output into the input of command B.
example: help | more
&&

Command A && Command B - means execute command A, Evaluate the errorlevel after running Command A, and if the exit code (errorlevel) is 0, only then execute command B.
example: cd\ &&cls && dir

||
Command A || command B - execute Command A, evaluate the exit code of this command and if it's anything but 0, Only then execute command B.
example: dir c:\windows || echo I can't find this directory c:\windows
>>
command A >> outputfile.txt - means execute command A, and write (append) the Output to outputfile.txt
example: dir c:\>> outputfile.txt, will add the "dir" output to the existing file or create a new one if not existing.
@
Commands beginning with the @ command are never echoed before running. The main use is to prevent batch echo by placing a command @echo off at the beginning of batch files.
:
A colon in front of a word, like :label , designates a label. Unlike remarks (REM), labels are not processed by the command processor, so comments might be added proceeded by a pair of colons.
example: ::, or by a colon and space.
;
Semicolons at the beginning of the line are usually processed by the command processor, but most other programs ignore these. This might be used to add a small batch file to the beginning of a program's data file, in the way that EXTPROC works.
/*
In PC DOS, OS/2 thus 4OS2, 4DOS, 4NT etc, a batch file beginning with /* is treated as a REXX script. PC DOS 7.0, 2000 and 7.1 implement this feature. In REXX, as in C, comments are surrounded by a matching /* comment */.
example: /* comment */
()
Commands surrounded by parentheses, "(" and ")", are treated as a single command. This is very useful to execute several commands in the same iteration of a FOR loop.

More links for DOS Command Line Operators

DOS Command List - Link to command list website

Technet - Product Documentation Pages



DOS Window Colors

Sets the default console foreground and background colors. "COLOR [attr]"

[attr] - Specifies color attribute of console output


Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground.  Each digit
can be any of the following values:

    0 = Black       8 = Gray
    1 = Blue        9 = Light Blue
    2 = Green       A = Light Green
    3 = Aqua        B = Light Aqua
    4 = Red         C = Light Red
    5 = Purple      D = Light Purple
    6 = Yellow      E = Light Yellow
    7 = White       F = Bright White

If no argument is given, this command restores the color to what it was
when CMD.EXE started.  This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.

The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.

Example: "COLOR fc" produces light red on bright white 



Check Hash Codes
Check a file’s hash on Windows

Open the Windows command prompt and use the certutil command for Windows.
An example of this simple command is below:

  • certutil -hashfile c:\Users\YourUserName\Desktop\filename.exe SHA256
  • certutil -hashfile c:\Users\YourUserName\Desktop\filename.exe MD5
The "SHA256" version gives the hash in the form: ECBEED67EFA864E558403F719B7FFD6F0192E77C36579B2FF9C2A0B6DD305752
The "MD5" version gives the hash in the form: 911a6223779dd825bc0c7cda1ce69a3