Every Windows system includes command prompt; and while a lot of people on Null Byte and WonderHowTo in general know how to use it, some people don't know anything about it, even how to access it.
Even if you aren't a Windows user, it's good to know how command prompt works because most operating systems have a similar interface for some of the commands.
Command prompt is easy to access, there are 4 common ways:
- Type "cmd" in the start menu's search box and press enter.
- Click on Run, then type "cmd" and press enter.
- Click on all programs in the start menu, click accessories and then click on command prompt.
- In Windows explorer, go to your hard drive's root and open the Windows directory, from here open the system 32 directory and then scroll down until you find Command Prompt.
Sometimes it is best to run command prompt as an administrator, although very few of the commands in this article require this.
One of the most common things I use command prompt for is network diagnostics. The simplest of these commands is "ping". This is very easy to use and can be used to test your connection to a website, find a website's IP address and to test your connection to an IP address, local or internet-based. To use the ping command you type:
You replace "Target" including the quotation marks with your target, here are three examples:
- ping example.com
- ping 220.127.116.11
- ping 192.168.0.1
Using the ping command with a local IP address you can determine whether a problem lies between your computer and your network or between your network and the website. It's also useful for finding the IP addresses of a website, there are a lot of different ways of doing this but using the command prompt is probably the easiest.
The other useful command is the ipconfig command, particularly:
This will produce a lot of useful information about your computer's network adapter and connection, including your physical, IPv4, and IPv6 addresses, as well as DNS servers and the name of your adapter.
There are several commands which can quickly solve network connection issues, far too many to list in this article. Google will usually help you to find out if commands can help, one example is that my computer had a problem with connecting to the internet, so I started up command prompt and used the ping command to test connection between my computer and my wireless router; the response was:
"PING: Transmit failed. General Failure"
I repeated the ping command with several different local IP addresses and all has the same response, showing the problem was between my computer and the router, rather than between the router and the internet. This was a new error to me, and after a short time on Google I discovered this command (Which does require administrator privileges):
netsh winsock reset catalog
This command solved my problem instantly, demonstrating the largely ignored power of the command prompt. I saved this in notepad as a script and now try it with most network issues.
The shutdown command is another useful command, particularly when controlling computers via a remote prompt. The shutdown command can perform several related actions, depending on the command entered. "/l" logs off, "/r" restarts, and "/p" shuts down the computer. "/i" will return a new window with options such as time and a warning, adding "/t ###" to another command means that the action will occur after a warning period of ### seconds. The following example will restart the computer after 30 seconds:
shutdown /r /t 030
There are many other commands which I have not covered on here, although these can all be viewed by typing the following in command prompt:
You can also use the command prompt to remotely shutdown other computers on your network with the right conditions, and like all of the other commands, the shutdown command can be included in a .bat or .cmd file using notepad, as I will explain later.
This command is one of the simplest available, it displays a prompt with the specified text in it. It is used like this:
This will display the word Hello, like this:
This can be useful in .bat and .cmd files, or when controlling a remote prompt. The echo command can also be used remotely on other local devices, and the effect could be increased with the colour command, for example:
This would turn the text green whilst keeping the black background, like this:
The first character determines the background colour (0), and the second determines the text colour (A). To see a full list of colours type "color help into the command prompt.
Command prompt is a useful resource, but not as easy as short-cuts in many cases, however scripts make command prompt more relevant asset. You do not need any special programs to make a script, only notepad. To make a script you open notepad and type a list of commands, each command on a new line. For example if I wanted to make a script which would execute the "netsh winsock reset catalog" command and then restart the computer after 30 seconds, I would type the following into notepad, as shown in the image below:
netsh winsock reset catalog
shutdown /r /t 030
The next step is to save the script as either a .bat or .cmd file, there is very little difference but some administrators prevent execution of .bat files, so I use .cmd. To save as a cmd file you open the "Save As" window, select "All Files" in the drop down box (1), choose a name for the file and add ".cmd" onto the end (2), as shown in this image:
To execute the script you would normally just double click it like a normal application, although in this case you would need to right click and run it as an administrator for the first command to work.
This guide was intended to act as a very basic introduction to Windows command prompt, and there are many other useful commands which I haven't covered. More info can be found on these commands through Google or by typing "Help" into the prompt.