Manage your Operating System using Command Prompt
In this chapter, we’ll continue where we left off the in the introduction to Command Prompt. We’ll learn how to manage applications using Windows package manager and task manager through CMD, run boot commands, and look up system information such as CPU, GPU, network stats, and more.
I’ll assume that you’re up to speed with the basics of CMD so we can kick it off with more intermediate topics. If you’re not, feel free to read the introduction article first.
System Commands
System Info
This command displays detailed configuration information about a computer and its operating system, including operating system configuration, security information, product ID, and hardware properties.
Desktop>systeminfo
Host Name: DESKTOP
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19045 N/A Build 19045
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: Mirza
Registered Organization:
Product ID: ...
Original Install Date: 2/11/2022, 3:57:17 AM
System Boot Time: 3/20/2023, 5:43:58 AM
System Manufacturer: Dell Inc.
System Model: Dell G15 5515
System Type: x64-based PC
BIOS Version: Dell Inc. 1.6.0, 3/14/2022
Windows Directory: C:\Windows
System Directory: C:\Windows\system32
Input Locale: en-us;English (United States)
Time Zone: (UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb
Total Physical Memory: 15,720 MB
Available Physical Memory: 6,668 MB
...
We can use WMIC for greater control.
> wmic os list full // OS Information
> wmic baseboard list full // Motherboard information
> wmic bios list full // BIOS information
> wmic diskdrive list full // Disk information
> wmic cpu list full // CPU information
> wmic path win32_videocontroller // GPU information
> wmic computersystem get totalphysicalmemory // RAM information
Booting
Supposedly we want to boot your machine. Command Prompt once again can help.
Using the shutdown -s
command we can set our machine to shut down after a brief period (after 30 seconds delay).
> shutdown -s
Otherwise, we can also restart it.
> shutdown -r
Either process can be scheduled to happen in the future. We can use the the timer flag -t
to specify when the command will be executed (in seconds).
> shutdown -s -t 3600 // shutdown in 1 hour
To set a different timer we first need to abort the previous one.
Using shutdown -i
command we can do either of the previous operations but using GUI.
The reason why there is a delay is so that if we made a mistake, we can quickly abort either process.
> shutdown -a // abort booting
We can also forcefully close all of the programs running on our machine (and sign out) using the following command:
> shutdown -f
Keep in mind that this process executes immediately (without delays).
For less aggressive commands we can use the Task Manager with the CMD.
To restart and start a BIOS upon booting use the command:
> shutdown /r /fw
Networking
In this module, we’ll go over the commonly used networking commands.
ipconfig
Starting with ipconfig
command that is used to retrieve TCP/IP network information on network adapters (the network you’re connected to), such as ip4, ip6 addresses, subnet mask, etc.
> ipconfig
We can customize this by passing different options like:
- ipconfig /all — lists all network addresses, including DNS, Hostname
- ipconfig /displaydns — retrieves a list of cached domains. Sites we visit are cached on our machine so that they open faster when visiting next time.
- ipconfig /flushdns — used to empty cached DNS.
- ipconfig /release & ipconfig /renew — used to troubleshoot your internet connection. Read more.
Also by typing ipconfig /?
we can see all available commands. More on ipconfig.
getmac
This command is used to retrieve information on the MAC address.
> getmac /v
Connection Name Network Adapter Physical Address Transport Name
=============== =============== =================== =================
Wi-Fi Wi-Fi xx-xx-xx-xx-xx-xx \Device\Tcpip
Ethernet Realtek Gaming xx-xx-xx-xx-xx-xx Media disconnected
Bluetooth Bluetooth Devic xx-xx-xx-xx-xx-xx Media disconnected
nslookup
This command displays Domain Name System (DNS) information for the requested site.
> nslookup website
netstat
The Network Statistics command retrieves all domains the machine is connected to.
Retrieving will take some time. We can speed up the process by returning the IP addresses only using netstat -n
ping
The ping command allows us to ping the other domains either using an IP address or domain name. If the connection is established the requested site should return packets.
Manage Applications with CMD
In this chapter, we’ll learn how to install, list out and uninstall applications via CMD.
Install Programs via CMD
CMD comes with a powerful package manager called Winget that lets us install apps on our machine.
To use it simply type winget
followed by the name of the app you want to install. Keep in mind that not every single program in the world is supported.
Let’s start by listing the options available.
> winget /?
usage: winget install [[-q] <query>] [<options>]
The following command aliases are available:
add
The following arguments are available:
-q,--query The query used to search
for a package
The following options are available:
-m,--manifest The path to the manifest of
the package
--id Filter results by id
--name Filter results by name
--moniker Filter results by moniker
-v,--version Use the specified version; default
is the latest version
-s,--source Find package using the
specified source
--scope Select install scope
(user or machine)
-a,--architecture Select the architecture to install
...
Let’s start with installing the Opera browser.
> winget install opera
Multiple packages found matching input criteria. Please refine the input.
Name Id Source
-----------------------------------
Opera GX XPDBZ4MPRKNN30 msstore
Opera Stable Opera.Opera winget
Oops! Looks like there are two Opera browsers to be installed. Let’s fix our command.
We’ll use the -s
command (source) to specify which exactly Opera app we want to install. We’re interested in a default browser, so the source will be winget.
> winget install opera -s winget
And the installation started.
Once the process is complete, the success message appears.
Desktop>winget install opera -s winget
Found Opera Stable [Opera.Opera] Version 90.0.4480.107
...
Successfully installed
If we open up a start menu and search for Opera, we can see that the app has indeed been installed.
See installed apps
Using winget list
command we can list out all programs we have installed on the machine.
Desktop>winget list
Name Id Version Available Source
-----------------------------------------------------------------------------------------------------------------------
NVM for Windows CoreyButler.NVMforWindows Unknown 1.1.10 winget
WhatsApp 5319275A.WhatsAppDesktop_cv1g1gvanyjgm 2.2308.4.0
Visual Studio Community 2022 Microsoft.VisualStudio.2022.Community 17.4.3 17.5.0 winget
AMD Radeon Software AdvancedMicroDevicesInc-2.AMDRadeonSoft… 10.20.40028.0
Audacity 3.1.3 Audacity.Audacity 3.1.3 3.2.4 winget
Bandicam MPEG-1 Decoder BandiMPEG1 1.2
Bandicam BandicamCompany.Bandicam 5.4.3.1923 6.0.2.2018 winget
Battle.net Battle.net Unknown
CCleaner Piriform.CCleaner 6.09 winget
Discord Discord.Discord 1.0.9007 1.0.9011 winget
Docker Desktop Docker.DockerDesktop 4.10.1 4.17.0 winget
Driver Booster 10 IObit.DriverBooster 10.2.0 winget Unknown
Git Git.Git 2.35.1.2 2.39.2 winget
Microsoft Edge Microsoft.Edge 110.0.1587.69 winget
Microsoft Edge Update Microsoft Edge Update 1.3.173.49
Microsoft Edge WebView2 Runtime Microsoft.EdgeWebView2Runtime 110.0.1587.63 winget
Microsoft Help Viewer 2.3 Microsoft Help Viewer 2.3 2.3.28307
Microsoft SQL Server 2022 (64-bit) Microsoft SQL Server SQL2022 Unknown
...
This of course returns a huge list. We can filter it using parameters such as id, name, and source. Let’s look for all programs with the name including the word “call”.
Desktop>winget list --name Call
Name Id Version
--------------------------------------------------------------------------------------------
Call of Duty 4: Modern Warfare Steam App 7940 Unknown
Or by its id, 7940:
Desktop>winget list --id 7940
Name Id Version
-----------------------------------------------------
Call of Duty 4: Modern Warfare Steam App 7940 Unknown
Upgrade Existing apps
If we attempt to install an app that it’s already there, winget will tell us about it and then update to the latest version.
And the latest package version has been installed.
> node -v
v19.7.0
Uninstall apps
As it turned out, I have two versions of Opera browser on my machine.
Desktop>winget list --name Opera
Name Id Version Source
----------------------------------------------------------------
Opera Stable 90.0.4480.107 Opera.Opera 90.0.4480.107 winget
Opera GX Stable 95.0.4635.74 Opera.OperaGX 95.0.4635.74 winget
I certainly do not need both. Let’s uninstall Opera GX.
First, let’s find the correct version using the id parameter.
Desktop>winget list --id Opera.OperaGX
Name Id Version Source
---------------------------------------------------------------
Opera GX Stable 95.0.4635.74 Opera.OperaGX 95.0.4635.74 winget
Ok, we got the right package. Now let’s use winget uninstall
to remove it.
Desktop>winget uninstall --id Opera.OperaGX
Found Opera GX Stable [Opera.OperaGX]
Starting package uninstall...
Successfully uninstalled
Desktop>
We can verify that the Opera GX is gone by searching for Opera with winget.
Desktop>winget list --name Opera
Name Id Version Source
----------------------------------------------------------------
Opera Stable 90.0.4480.107 Opera.Opera 90.0.4480.107 winget
Winget upgrade
It’s a good idea to regularly upgrade all software. To do that use upgrade
command.
> winget upgrade
Task Manager
The most common problem solver on Windows is non-other than the Task Manager. Did you know that you also run a Task Manager within the Command Prompt?
If we open up a Command Prompt and type @tasklist
it will return a list of active processes on the machine:
Desktop>@tasklist
Image Name PID Session Name Session# Mem Usage
====================== ======== ================ =========== ============
...
Here we can see all programs running on my PC. Among dozens of instances of Google Chrome, there is also a VLC player.
To find a particular process we can filter the task list using the find-string command:
Desktop>@tasklist | findstr vlc.exe
vlc.exe 21632 Console 1 186,392 K
We can retrieve more information on a running process using wmic and the Process Id (PID), 21632.
Desktop>wmic process 21632
This, among other details, returns the title of the video that is streaming in the VLC player at the moment.
...
C:\Program Files\VideoLAN\VLC\vlc.exe" --started-from-file
"C:\Users\Mirza\Videos\mirzly cqb sniper csgo.mp4
To terminate this process we can look up the Process Id (PID), 21632, and call taskkill
upon it.
Desktop>taskkill /f /pid 21632
SUCCESS: The process with PID 21632 has been terminated.
Where
- /f — forcefully terminates the process
- /pid — unique identifier for each program (Process Id)
The program is now shut down. We can verify that by running the tasklist command and look for VLC.
Desktop>@tasklist | findstr VLC.exe
// VLC process is no where to be found
Another way to terminate the program is to look for it by name:
Desktop>taskkill /f /im VLC.exe
SUCCESS: The process "VLC.exe" with PID 21632 has been terminated.
Where /im
represents the image name (name of the running program).
Customization
Title
One of the features of CMD is to change the value in the title bar. Right now it says Administration: Command Prompt.
That’s cute, but let’s rename it using title
command.
Prompt
We can change the prompt text from displaying the current path to displaying just about anything.
> prompt iron man
The prompt will stay the same no matter which directory we enter.
Although it looks better, I prefer adding some type of delimiter at the end for better readability because now the commands are glued to the path named.
To fix this we’ll once again set prompt, only this time we’ll make use of $g at the end which stands for greater than (>) or $$ (for dollar)
To reset the prompt simply type prompt
and hit enter key.
A full list of commands can be seen using /?
command.
> prompt /?
CMD Window Size
We can change the CMD window size on the fly using commands. The command we’re interested in is called mode
followed by width, height
.
Colors
Command Prompt styles can be customized in two ways, either by right-clicking on the title bar and then clicking on properties or using commands. I prefer the latter.
Starting with a list of color commands:
Desktop>color /?
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.
We can see that we can make a combination of letters and numbers for different themes. Let’s give it a try.
To reset the theme back to the default one type color 07
.
In the final part of the series, we’ll look into how to make HTTP requests from CMD using CURL, how to protect data and write our own Batch Scripts.