Essential Command Prompt Commands for PC Optimization & Security

By Austin Nammack
December 3, 2025
15 min read

The Windows Command Prompt is a powerful tool that many users overlook. With just a few simple commands, you can optimize your PC's performance, enhance security, troubleshoot issues, and maintain system health. This comprehensive guide covers the essential commands every Windows user should know to keep their computer running smoothly and safely.

Important Safety Notice

Always run Command Prompt as Administrator for these commands to work properly. Right-click the Command Prompt icon and select "Run as administrator". Some commands can affect system files, so follow instructions carefully and create a system restore point before making major changes.

System Performance Optimization

Clean Temporary Files

Disk Cleanup Command cleanmgr /sagerun:1
What it does: Removes temporary files, cache, and unnecessary system files that accumulate over time and slow down your PC.
When to use: Run monthly or when disk space is low.
Clear DNS Cache ipconfig /flushdns
What it does: Clears your DNS resolver cache, which can fix internet connectivity issues and speed up browsing.
When to use: When experiencing slow internet or website loading issues.

Disk Health & Optimization

Check Disk for Errors chkdsk C: /f /r
What it does: Scans your hard drive for errors and attempts to repair them. The /f flag fixes errors, and /r locates bad sectors and recovers readable information.
When to use: If you suspect disk corruption or experience frequent crashes. Requires restart.
Optimize and Defragment Drive defrag C: /O
What it does: Defragments your hard drive for faster file access (for HDDs only, not SSDs).
When to use: Monthly for traditional hard drives. Don't use on SSDs.

Memory & Resource Management

View Memory Usage systeminfo | findstr /C:"Total Physical Memory" /C:"Available Physical Memory"
What it does: Shows how much RAM your system has and how much is currently available.
When to use: To check if you need more RAM or if programs are using too much memory.
View Running Processes tasklist
What it does: Lists all currently running processes and programs.
When to use: To identify resource-hogging applications.
Kill Unresponsive Process taskkill /IM processname.exe /F
What it does: Forcefully closes a frozen or unresponsive program.
Example: taskkill /IM chrome.exe /F to force-close Chrome.

Security & System Protection

System File Integrity

System File Checker sfc /scannow
What it does: Scans all protected system files and replaces corrupted files with cached copies.
When to use: When experiencing system crashes, blue screens, or strange behavior. Takes 15-30 minutes.
DISM Repair Tool DISM /Online /Cleanup-Image /RestoreHealth
What it does: Repairs the Windows system image and component store. Run this BEFORE sfc /scannow if that command finds errors.
When to use: When sfc /scannow reports it cannot fix certain files.

Security Scanning

Windows Defender Quick Scan "%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 1
What it does: Runs a quick malware scan using Windows Defender.
When to use: Daily or when you suspect malware.
Windows Defender Full Scan "%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2
What it does: Performs a comprehensive system scan for malware and threats.
When to use: Weekly or monthly deep security check.

Network Security

View Active Network Connections netstat -ano
What it does: Shows all active network connections and listening ports. Helps identify suspicious network activity.
When to use: To check if unknown programs are accessing the internet.
Reset Network Settings netsh winsock reset
What it does: Resets network configuration to defaults, fixing many internet connection issues.
When to use: When experiencing persistent network problems. Requires restart.
Show Wi-Fi Passwords netsh wlan show profile name="NetworkName" key=clear
What it does: Displays the saved password for a specific Wi-Fi network.
Example: Replace "NetworkName" with your actual network name.

System Information & Diagnostics

System Details

Comprehensive System Information systeminfo
What it does: Displays detailed configuration information about your computer and operating system.
When to use: When you need to know your Windows version, processor, RAM, or other hardware details.
Check Windows Version winver
What it does: Opens a window showing your Windows version and build number.
When to use: To verify if your Windows is up to date.

Battery Health (Laptops)

Generate Battery Report powercfg /batteryreport
What it does: Creates a detailed HTML report about your battery's health, capacity, and usage history. Saved to C:\Windows\System32\battery-report.html
When to use: To check battery degradation on laptops.
Energy Efficiency Report powercfg /energy
What it does: Analyzes your system for energy efficiency issues and generates a report.
When to use: To optimize battery life and power consumption.

Drive Information

List All Drives wmic logicaldisk get name,size,freespace
What it does: Shows all drives, their total size, and available free space.
When to use: To quickly check storage capacity across all drives.
Check Drive Health (SMART Status) wmic diskdrive get status
What it does: Displays the health status of all physical drives. "OK" means healthy.
When to use: Regular maintenance check to predict drive failure.

Maintenance & Updates

Windows Updates

Check for Windows Updates wuauclt /detectnow /updatenow
What it does: Forces Windows to check for and download available updates immediately.
When to use: When automatic updates seem stuck or delayed.

System Cleanup

Clear Windows Update Cache net stop wuauserv
rd /s /q C:\Windows\SoftwareDistribution
net start wuauserv
What it does: Stops Windows Update service, deletes the update cache, and restarts the service. Fixes stuck updates.
When to use: When Windows Updates fail repeatedly.
Empty Recycle Bin rd /s /q %systemdrive%\$Recycle.bin
What it does: Permanently deletes all files in the Recycle Bin.
When to use: To free up disk space quickly.

System Restore

Create Restore Point wmic.exe /Namespace:\\root\default Path SystemRestore Call CreateRestorePoint "Manual Restore Point", 100, 7
What it does: Creates a system restore point that you can revert to if something goes wrong.
When to use: Before installing new software or making system changes.

Pro Tips

Quick Reference Command List

Daily/Weekly Maintenance

  1. ipconfig /flushdns - Clear DNS cache
  2. cleanmgr /sagerun:1 - Clean temporary files
  3. "%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 1 - Quick malware scan

Monthly Maintenance

  1. sfc /scannow - Check system file integrity
  2. chkdsk C: /f /r - Check disk for errors
  3. wmic diskdrive get status - Check drive health
  4. defrag C: /O - Optimize drives (HDD only)

Troubleshooting

  1. netsh winsock reset - Fix network issues
  2. DISM /Online /Cleanup-Image /RestoreHealth - Repair system image
  3. tasklist and taskkill - Manage frozen programs
  4. netstat -ano - Check network connections

Remember

Conclusion

Mastering these Command Prompt commands empowers you to maintain, optimize, and secure your Windows PC like a pro. Regular use of these maintenance commands can prevent many common issues, improve system performance, and extend your computer's lifespan. Start with the basic commands and gradually incorporate more advanced ones into your maintenance routine.

Remember, the Command Prompt is a powerful tool—with great power comes great responsibility. Always double-check commands before executing them, and when in doubt, research or consult with an expert. Happy optimizing!

Written by Austin Nammack

Austin Nammack is a web development expert and PC optimization specialist at RamStar Web Development. With years of experience in system administration and performance tuning, Austin helps users get the most out of their Windows machines through practical, easy-to-follow guides.