How To Command Prompt

How To Command Prompt

Reading time1 min
#Windows#Networking#Automation#CommandPrompt#BatchScripts#Troubleshooting

Mastering Command Prompt: Practical Windows Troubleshooting from the Shell

The first call when a system breaks at 2 a.m. isn't about clicking around menus—it's about running diagnostics with minimal dependencies. The Windows Command Prompt remains critical for direct troubleshooting, particularly when the graphical shell is inaccessible or unreliable.


Command Prompt Access and Context

Access levels matter. Many core diagnostics require admin privileges. Either:

  • Press Win+Rcmd → Enter (standard shell)
  • Right-click CMD shortcut → “Run as administrator” (for disk, system, and networking commands requiring elevation)

Network security policies on corporate endpoints may restrict CMD or batch script execution. Confirm your user permissions in advance.


Key Commands for Real-World Failures

Network Diagnostics: ipconfig and ping

Scenario: Reports of intermittent connectivity, DNS lookup failures, or lost authentication.

Jump to command line:

ipconfig /all

Inspects interface status, lease times, DNS discovery. Notably, check for:

  • 169.254.x.x addresses (APIPA, indicating DHCP failure)
  • Incorrect DNS suffixes

If DHCP renewal is required or ARP cache poisoning suspected:

ipconfig /release
ipconfig /renew
ipconfig /flushdns

Note: Flushing the DNS resolver cache (/flushdns) solves cached records but not up/downstream DNS failures.

Test end-to-end connectivity in network segmentation scenarios:

ping 8.8.8.8
ping internalfileserver.corp

If ICMP packets drop to the gateway but not beyond, investigate VLAN or firewall configuration.

Non-obvious: Windows firewalls may silently drop ICMP. Use -4/-6 to specify IP family as needed.


System Health: sfc and chkdsk

Bit rot and abrupt shutdowns often corrupt OS files. Quick validity check:

sfc /scannow
  • Requires elevated CMD.
  • CBS.log will log details (see C:\Windows\Logs\CBS).

I've seen sfc complete with no errors shown, yet application layer issues persist. Disk issues are a common underlying cause:

chkdsk C: /f /r /x

Options explained:

  • /f fixes logical file system errors.
  • /r checks and recovers bad sectors (slower, invokes physical disk checks).
  • /x attempts to dismount the target volume (can cause service interruptions—schedule outside of business hours).

Gotcha: For boot drive (C:), expect prompt to schedule scan on next reboot, not instant execution.


Process Control: tasklist and taskkill

Tracking resource leaks or rogue processes rarely needs Task Manager—especially on RDP-limited servers.

Current process inventory:

tasklist /v

Includes CPU time, session name for multiuser TS systems.

Forcefully end a hung process:

taskkill /PID 1234 /F

Or by image name:

taskkill /IM explorer.exe /F

Known issue: Sometimes /F fails due to permissions or process tree dependencies—in that case, check for child processes, and be cautious: forced termination can cause unsaved work loss or trigger watchdog reboots.


Automation via Batch Scripts

Manual repetition for resets or diagnostics is error-prone. Batch scripting reduces this friction. A routine network repair script:

@echo off
echo [*] Resetting Winsock catalog...
netsh winsock reset

echo [*] Flushing DNS and renewing interface...
ipconfig /flushdns
ipconfig /release
ipconfig /renew

echo [*] Disabling/enabling adapters (replace "Ethernet" if needed)
netsh interface set interface "Ethernet" admin=disable
timeout /t 2 /nobreak >nul
netsh interface set interface "Ethernet" admin=enable

echo [*] Complete. Check results with ipconfig /all.
pause

Side note: Interface name varies across devices—verify via netsh interface show interface.
Scripts must be run as administrator for network stack changes.


Advanced and Time-Saving Patterns

  • Tab-completion: Use Tab for file/directory auto-complete—critical in long directory paths or hidden system folders.
  • Multiple command chaining: Use &&/|| for dependency execution, e.g.,
    ipconfig /release && ipconfig /renew && ipconfig /flushdns
    
    (Halts on error; avoids partial execution.)
  • Log redirection: Send output directly to files for after-action reviews:
    sfc /scannow > %USERPROFILE%\Desktop\sfc-log.txt 2>&1
    
  • Version check: Correlate issues to OS build,
    ver
    systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
    

Table: Common Troubleshooting Commands

CommandTypical UseNotes
ipconfig /allNetwork adapter statusCheck for APIPA addresses
netstat -anPort listening/connection inventoryCombine with findstr
sfc /scannowSystem integrity checkElevated only; check logs
chkdsk C: /f /r /xDisk health, recoveryScheduling may be required
tasklist /vList running processes/svc for services display
taskkill /PID #### /FTerminate stuck processBeware forced shutdowns

Not Perfect, But Indispensable

Windows Command Prompt scripting isn’t as robust as PowerShell—lacks objects, has awkward error handling—but its availability during system emergencies and WinRE mode compensates. Learning these core techniques means less guessing when a problem escalates.

Questions or edge cases welcome—actual break/fix scenarios often yield new tricks.


Note: For persistent or reproducible failures, escalate to Windows Event Logs (eventvwr.msc) or PowerShell advanced diagnostics (Get-WinEvent)—CMD is often just the first responder.