Determining the default gateway and subnet mask from a Windows command prompt
From a command prompt on a
Microsoft Windows system, you can obtain details on the network configuration
by issuing the command ipconfig
or ipconfig /all
, if
you wish to see more details. If you are only interested in a specific value or
values, though, you can
pipe the output
of the command to the findstr
command. If you wish to see multiple values, e.g., the subnet mask and the
default gateway address, you can put text associated with both values,
separated by a space, within double quotes. Findstr will treat the space
between strings as instructing it to perform a
logical OR
operation, i.e., it will find any lines that contain either of the strings.
Findstr uses a case sensitive search, so you need to either match the case of
the text or use the /i
option with findstr, which instructs it to
ignore the case of text and perform a case insensitive search.
C:\>ipconfig | findstr "Mask Gateway"
Subnet Mask . . . . . . . . . . . : 255.255.255.224
Default Gateway . . . . . . . . . : 192.168.1.1
C:\>ipconfig | findstr "mask gateway"
C:\>ipconfig /all | findstr /i "mask gateway"
Subnet Mask . . . . . . . . . . . : 255.255.255.224
Default Gateway . . . . . . . . . : 192.168.1.1
C:\>
You can also use a
Windows Management Instrumentation Command-line (WMIC) command to obtain
the same information.
C:\>wmic nicconfig get defaultIPGateway, IPSubnet
DefaultIPGateway IPSubnet
{"192.168.1.1"} {"255.255.255.224", "64"}
C:\>
[/os/windows/commands]
permanent link
Obtaining information on a CD/DVD drive with WMIC
If you want to determine the model number of an optical drive, such as
a CD or DVD drive, in a system running a Microsoft Windows operating system
from a command-line interface (CLI), you can
open a command prompt window
and issue a Windows Management
Instrumentation Command-line (WMIC) command:
wmic cdrom get name
(the value for
caption
may return the same information). E.g.:
C:\>wmic cdrom get name
Name
HL-DT-ST DVD-ROM DU90N
C:\>wmic cdrom get caption
Caption
HL-DT-ST DVD-ROM DU90N
C:\>
If you wish to determine whether media, such as a CD or DVD, is in the
drive, you can use the command wmic cdrom get medialoaded
. If
there is no disc in the drive, the value for MediaLoaded
will be
FALSE
. If there is a disc in the drive, the value will be true
as in the example below where there is a CD in the drive.
C:\>wmic cdrom get medialoaded
MediaLoaded
TRUE
C:\>
[ More Info ]
[/os/windows/commands/wmic]
permanent link
Getting the video resolution on a Windows system
If you need to determine the horizontal and vertical video resolution of the
system you are working on from a command-line interface (CLI) on a Microsoft
Windows systeem, you can open a
PowerShell window
(you can type PowerShell
in the Windows "search" field and
click on PowerShell when you see it in the returned results) and
issue the
Windows Management Instrumentation Command-line (WMIC) command
Get-WmiObject win32_videocontroller | select caption, CurrentHorizontalResolution, CurrentVerticalResolution
.
PS C:\> Get-WmiObject win32_videocontroller | select caption, CurrentHorizontalResolution, CurrentVerticalResolution
caption CurrentHorizontalResolution CurrentVerticalResolution
------- --------------------------- -------------------------
NVIDIA Quadro K2000 2560 1440
PS C:\>
If you need to determine the resolution on another system in the same
Windows domain on
the local area network (LAN), you can add -ComputerName
followed
by the name of the computer to the command as shown below.
PS C:\> Get-WmiObject -ComputerName apollo win32_videocontroller | select caption, CurrentHorizontalResolution, CurrentVerticalResolution
caption CurrentHorizontalResolution CurrentVerticalResolution
------- --------------------------- -------------------------
Microsoft Basic Display Adapter 1024 768
PS C:\>
[ More Info ]
[/os/windows/commands/wmic]
permanent link
Obtaining processor information with WMIC
You can obtain information on the
Central
Processing Unit (CPU) in a system
running a Microsoft Windows
operating system
(OS) using
Windows Management Instrumentation Command-line (WMIC) commands. To
see the value of all parameters,
open a command prompt window
and issue the command wmic /namespace:\\root\cimv2 path win32_processor
get /format:list
(using the /format option, you can see the information
in a more readable fashion).
C:\>wmic /namespace:\\root\cimv2 path win32_processor get /format:list
AddressWidth=64
Architecture=9
AssetTag=UNKNOWN
Availability=3
Caption=Intel64 Family 6 Model 85 Stepping 4
Characteristics=252
ConfigManagerErrorCode=
ConfigManagerUserConfig=
CpuStatus=1
CreationClassName=Win32_Processor
CurrentClockSpeed=2195
CurrentVoltage=16
DataWidth=64
Description=Intel64 Family 6 Model 85 Stepping 4
DeviceID=CPU0
ErrorCleared=
ErrorDescription=
ExtClock=100
Family=179
InstallDate=
L2CacheSize=14336
L2CacheSpeed=
L3CacheSize=19712
L3CacheSpeed=0
LastErrorCode=
Level=6
LoadPercentage=3
Manufacturer=GenuineIntel
MaxClockSpeed=2195
Name=Intel(R) Xeon(R) Gold 5120 CPU @ 2.20GHz
NumberOfCores=14
NumberOfEnabledCore=14
NumberOfLogicalProcessors=28
OtherFamilyDescription=
PartNumber=
PNPDeviceID=
PowerManagementCapabilities=
PowerManagementSupported=FALSE
ProcessorId=BFEBFBFF00050654
ProcessorType=3
Revision=21764
Role=CPU
SecondLevelAddressTranslationExtensions=TRUE
SerialNumber=
SocketDesignation=CPU0
Status=OK
StatusInfo=3
Stepping=
SystemCreationClassName=Win32_ComputerSystem
SystemName=MUNICH
ThreadCount=28
UniqueId=
UpgradeMethod=1
Version=
VirtualizationFirmwareEnabled=TRUE
VMMonitorModeExtensions=TRUE
VoltageCaps=
C:\>
[ More Info ]
[/os/windows/commands/wmic]
permanent link
Running an application under another account on a Windows system with runas
If you are logged into a system running the Microsoft Windows operating system
and wish to run an application, e.g., Microsoft Outlook, under another account
other than the one you are currently logged in under without switching to that
other account, you can run the application as the other user using the
runas
command from a command prompt. If you don't know where the
application is located on the system, you can find its location from a
command
prompt by changing the directory to the root directory of the drive where
applications are stored, which is typically drive C:, then use the
/s
option of the dir
command to search all
subdirectories for the program, e.g., outlook.exe, which is the executable
file for Microsoft Outlook.
C:\Program Files\Microsoft Office>cd \
C:\>dir /s outlook.exe
Volume in drive C has no label.
Volume Serial Number is 9420-A68C
Directory of C:\Program Files (x86)\Microsoft Office\Office14
03/16/2021 12:41 AM 15,794,840 OUTLOOK.EXE
1 File(s) 15,794,840 bytes
Directory of C:\Windows\Installer\$PatchCache$\Managed\00004109D30000000000000000F01FEC\14.0.4763
03/23/2010 12:57 PM 15,889,248 OUTLOOK.EXE
1 File(s) 15,889,248 bytes
Total Files Listed:
2 File(s) 31,684,088 bytes
0 Dir(s) 3,328,741,376 bytes free
C:\>
In the example above, the program is located in the
C:\Program Files (x86)\Microsoft Office\Office14
directory, so
I can start the application as the user jdoe in the
Windows domain
Mordor with the command below (enclose the directory path and application
name in double quotes if there are spaces in the directory path):
C:\>runas /user:mordor\jdoe "C:\Program Files (x86)\Microsoft Office\Office14\Outlook.exe"
Enter the password for mordor\jdoe:
Attempting to start C:\Program Files (x86)\Microsoft Office\Office14\Outlook.exe as user "mordor\jdoe" ...
C:\>
If the account under which I wanted to run Outlook is not in a Windows
domain, but is, instead, an account on the same computer, I could omit the
domain specification and just use /user:jdoe
. You can also
use the format user@domain
, e.g., jdoe@mordor.lan
,
instead of the format domainname\username
. To run a program as
another user, you will need to know the password for the other account.
In this case, the graphical user interface (GUI) for Outlook will open with
the email, calendar entries, tasks, and contacts for the domain jdoe account
once the password for that account is provided.
[/os/windows/commands]
permanent link
Performing a bare metal backup on a Windows 10 system
If you want to perform a "bare metal" backup of a Microsoft Windows 10 system
to an external USB
drive without a third-party application, you can use the
Backup and Restore utility that is provided by Microsoft with the
operating system. You can run the program from a command-line interface
(CLI) by
opening a command prompt window with
administrator privileges and issuing the command wbadmin start
backup -backupTarget:x -allcritical -quiet
where x
is the drive letter for the drive where you wish to store the backup.
When you add the -quiet
option, the backup will be run with no
prompts for the user. The --allcritical
option "creates a backup
that includes all critical volumes (critical volumes contain the operating
system files and components)."
[ More Info ]
[/os/windows/commands]
permanent link
Deleting old Windows backups with wbadmin
I had set up the built-in Windows 7 backup utility to run on my
mother-in-law's Windows 10 PC to back up the computer's internal hard
disk drive (HDD) to an external
USB drive. She asked me to verify that the backup was
still functioning, so I checked the status of the backup process on her
Windows 10 (version 1709) system
using the wbadmin
command by
opening a command prompt
window with administrator access to run the
wbadmin get versions
command to obtain a list of all the
backups. I found that the last backup had occurred on December 31, 2017.
[ More Info ]
[/os/windows/commands]
permanent link
Checking operating system information with WMIC
You can use wmic os get
commands on a Microsoft Windows system
to view information related to the operating system via a command-line
interface (CLI). E.g., to determine the version of the operating system you
can issue the command
Windows Management Instrumentation Command-line (WMIC)
command wmic os get version
.
C:\Users\Public>wmic os get version
Version
10.0.15063
C:\Users\Public>
Or if you know the system is running a particular version of the Windows
operating system, e.g., Windows 10, but want to see just the build number
for that version of Windows, you could issue the command wmic os get
BuildNumber
.
C:\Users\Public>wmic os get BuildNumber
BuildNumber
15063
C:\Users\Public>
[ More Info ]
[/os/windows/commands/wmic]
permanent link
Determining the antivirus software on a Windows system from the command line
You can determine the antivirus software present on a system, if the
antivirus software is registered with the Windows Security Center, using
Windows Management Instrumentation Command-line (WMIC).
E.g., for a Windows 10 system using Microsoft
Windows Defender:
C:\>WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName
displayName
Windows Defender
C:\>
[ More Info ]
[/os/windows/commands/wmic]
permanent link
Displaying date and time information on a Microsoft Windows system
You can use the date and
time commands on a Microsoft Windows system to
display current date and time information:
C:\Users\Lila>date /t
Sat 08/26/2017
C:\Users\Lila>time /t
02:07 PM
C:\Users\Lila>
Placing /t
after the commands results in the current date
and time information being displayed without an accompanying prompt to change
the current settings.
You can display the information in a different format using
the
Windows Management Instrumentation Command-line (WMIC) command shown below:
C:\Users\Lila>wmic path win32_utctime get * /format:list
Day=26
DayOfWeek=6
Hour=18
Milliseconds=
Minute=16
Month=8
Quarter=3
Second=19
WeekInMonth=4
Year=2017
C:\Users\Lila>
[ More Info ]
[/os/windows/commands]
permanent link