Do CMD commands to check if your computer is infected actually work?
Short answer: no — not by themselves. Microsoft’s own support forum says it plainly: neither the Windows Command Prompt nor PowerShell has any built-in malware detection or remediation. The black window can show you open connections, running processes, and damaged system files — but it cannot tell you whether any file is a virus. Only one command in this post actually scans for malware, and it is the Defender PowerShell scan at the end.
That does not make the other commands useless. It makes them a flashlight, not a scanner. Used right, they can show you the signs that something is wrong — a strange connection, a process that will not die, a system file that keeps failing to repair. Used wrong, they will do nothing except waste your time, or worse, convince you the PC is clean when it is not. This post teaches each command honestly: what it shows, what it cannot show, and when to stop typing and run a real scan.

What Can CMD Commands Actually Detect?
Almost nothing, directly. That is the fact this whole post is built on, and it is not my opinion. On Microsoft’s own support forum, a Microsoft Q&A answer states it in one sentence: “We don’t really have any built-in malware detection or remediation capabilities in either the Windows Command Prompt or the PowerShell Prompt.” The Command Prompt was built to run commands, not to judge files. It has no database of known viruses, no behavior analysis, and no way to tell a clean file from an infected one.
So what are the commands below for? They are for looking. A connection list can show you a program talking to a server it has no business talking to. A process list can show you a program running from a strange folder, or a program that restarts itself every time you kill it. A system-file check can show you that Windows itself has been damaged — which is a sign something was here, even if it does not name the something. Each command gives you a clue. None of them gives you a verdict.
The one exception is the last command in this post, Start-MpScan. That is not a Command Prompt command at all — it is a PowerShell command that tells Windows Defender to scan. It works because it hands the job to Defender, which does have a virus database. Everything else in this post is preparation for that scan: gathering clues, narrowing the suspects, and knowing whether the scan’s result can be trusted.
One more honest point before the commands. If your PC is already showing the classic signs — it is suddenly slow, pop-ups appear, your browser homepage changed, friends are getting strange messages from you — you do not need a command to tell you something is wrong. Start with the scan. The commands are for the grey area: the PC feels off but nothing is obvious, and you want to look before you call in the scanner.
How Do I Open Command Prompt as an Administrator?
Several commands in this post need administrator rights. A normal Command Prompt window will run them and then fail, or show you a short list when the real list is longer. Opening it as administrator takes five seconds and avoids half the confusion people run into.
Press the Windows key, type cmd, and when Command Prompt appears in the results, right-click it and choose Run as administrator. Click Yes on the prompt that follows. The window that opens has Administrator in its title bar — that is how you know it worked. If it does not say Administrator, close it and try again.
One note: the Start-MpScan command at the end of this post does not run in Command Prompt at all. It runs in PowerShell. Open it the same way: press the Windows key, type PowerShell, right-click Windows PowerShell, and choose Run as administrator. The two windows look similar — both black, both full of text — but they are different tools, and the last section tells you exactly which window to use.
Everything in this post is read-only except the scan itself. The commands show you information; they do not change, delete, or quarantine anything. That is deliberate. You are looking, not fixing, until the final section.
Can netstat -ano Show Me If Something Is Talking to a Hacker?
Type netstat -ano and press Enter. A list appears: every connection your PC currently has open, with the protocol, the local address, the foreign address, the state, and a number at the end called the PID — the process ID, which tells you which program owns the connection.
What you are looking for is a connection that does not belong. A normal PC has dozens of connections open to Microsoft, Google, your cloud storage, and your browser’s servers. A suspicious one is a connection to an address in a country you have no connection to, at a time when you are not doing anything, owned by a process you do not recognize. The foreign address column is where that shows up.
Here is what netstat cannot tell you, and this is where most guides stop being honest. It cannot tell you whether a connection is safe. A connection to a strange-looking address can be a perfectly normal content-delivery server, and a connection to a familiar-looking address can be malware using a real service as cover. It cannot tell you what is being sent — only that something is connected. And the list changes every second, so a connection that looks odd now may be gone before you can investigate it.
To use it properly, run it twice: once when the PC is idle and once when the suspicious behavior is happening. Note the PIDs that appear in the second run but not the first. Then find what those PIDs are: type tasklist /fi “PID eq 1234”, replacing 1234 with the PID number, and it will show you the program name. If that program is one you installed and recognize, the connection is probably fine. If it is a program you do not recognize, or a program running from a folder in your user profile or a temp folder, that is the clue worth following — and the next section shows you how to look at that program properly.
| Command | What it shows you | What it cannot show you |
|---|---|---|
| netstat -ano | Every open connection, with the foreign address and the process ID that owns it | Whether a connection is safe, or what data is being sent |
| tasklist /svc | Every running process, with the services it hosts and the memory it uses | Whether a process is malware — a name is not a verdict |
| sfc /scannow | Whether Windows system files are damaged, and whether it could repair them | Whether a virus caused the damage, or whether your files are safe |
| attrib | Which files have the hidden attribute set, in a folder you choose | Whether a hidden file is malicious — most hidden files are normal |
| Start-MpScan | The one command that actually scans: it tells Windows Defender to check your files | Nothing on its own — it still needs the scan to finish and a second opinion to be sure |
What Does tasklist Tell Me About Suspicious Processes?
Type tasklist /svc and press Enter. A list appears of every process running on your PC, with the services each one hosts and the memory it is using. This is the companion to netstat: netstat shows you the connections, tasklist shows you the programs behind them.
What you are looking for is a process that does not belong. The signs are the same ones a technician looks for: a name that imitates a real Windows process but is spelled slightly differently, a process running from a strange location, or a process using far more CPU or memory than it should. The location is the strongest clue — a real Windows process runs from C:\Windows\System32. The same name running from a folder inside your user profile, or from a temp folder, is not the real one.
To see the location, use tasklist /v. The /v switch adds a column showing the window title and the path information for each process, which is what you need to tell the real svchost.exe from the fake one. If you find a suspect, do not delete it. Note its name and path, then close this window and run the Defender scan in the last section — deletion by hand is how people break their own PCs, because the file you delete by hand may be a system file the malware was imitating.
There is one more honest limit here. A process list shows you what is running right now. Malware that only runs at startup, or only runs when you open a particular program, will not be in the list when you look. That is why this post also covers the logs: if a process keeps coming back after every removal, our guide to what to do when Defender keeps finding the same trojan walks through finding the scheduled task or startup entry that restarts it.
Will sfc /scannow Remove a Virus?
No. This is the most misunderstood command in this post, and it is worth being exact about. sfc /scannow — System File Checker — checks whether Windows’ own system files have been damaged and repairs them from a clean copy. It does not look for viruses, it does not remove viruses, and a clean result does not mean your PC is clean.
What it does show you is damage. If a virus, or a bad update, or a failing drive has corrupted Windows files, sfc finds it. The command takes a while — ten to twenty minutes on most PCs — and you should not close the window before it finishes. There are three possible results, and they mean very different things.
If it says “Windows Resource Protection did not find any integrity violations,” your system files are intact. That is good news about Windows, and no news about malware — a virus can live happily in your user folders without ever touching a system file.
If it says “Windows Resource Protection found corrupt files and successfully repaired them,” the repair worked. Run it once more to confirm, then run the Defender scan anyway, because the damage may have been caused by something that is still there.
If it says “Windows Resource Protection found corrupt files but was unable to fix some of them,” the repair failed. The fix is to run DISM first — type DISM /Online /Cleanup-Image /RestoreHealth and press Enter, wait for it to finish, then run sfc /scannow again. DISM downloads clean copies of the damaged files from Windows Update. If sfc still cannot repair them after DISM, the damage is deeper than a file check can fix, and that is the point to take the PC to a technician rather than keep running commands.
One caution: some guides tell you to run sfc as the first step when you suspect a virus. That is backwards. A damaged system file is a symptom, not a diagnosis, and repairing it while the malware is still active is like bandaging a wound while the knife is still in it. Run the scan first. Use sfc afterwards, to repair whatever the malware broke.
Can the attrib Command Reveal Hidden Malware?
The attrib command shows you file attributes — whether a file is hidden, read-only, or a system file. The trick it is famous for is this: type attrib +h to hide a file, or attrib -h to unhide one, and add /s to do it for a whole folder and its subfolders. Malware sometimes hides its files by setting the hidden attribute, so the idea is to unhide everything and see what appears.
The honest version is less exciting. Hidden does not mean malicious. Windows hides thousands of files by default — system files, program data, your own browser cache — and unhiding them all will flood you with entries that are completely normal. The command cannot tell you which hidden file is malware and which is a Windows component. It shows you an attribute, not a verdict.
There is one narrow case where it helps. If a USB drive suddenly shows as empty when you know it has files on it, and attrib on that drive reveals the files with the hidden attribute set, that is a classic sign of a USB-spreading infection — the malware hid your files and put a shortcut in their place. In that case, do not open the shortcut. Run attrib -h -r -s /s /d X:\*.* — replacing X with the drive letter — to restore your files, then scan the drive with Defender before opening anything on it.
Outside that case, treat attrib as a curiosity, not a diagnostic. If you find a hidden file with a strange name in a strange folder, note it down and let the Defender scan judge it. The command’s job is to show you the file exists. Deciding what it is belongs to the scanner.
How Do Scammers Use These Commands Against You?
This section exists because the commands in this post are the same ones tech-support scammers use, and you should know the trick before someone uses it on you.
The scam goes like this. A pop-up, or a cold call, tells you your PC is infected and a technician will help you. The “technician” asks you to open Command Prompt and type netstat -ano, or tasklist, or a similar command. A list appears — dozens of connections, dozens of processes — and the scammer points at it and says, “Look, see all those foreign addresses? See all those programs? Your PC is full of hackers.” It looks convincing, because the list is real. What is fake is the interpretation: those connections and processes are normal. Every PC in the world shows the same list.
Then comes the second half. The scammer asks you to type a command that downloads their remote-access tool, or to grant them access so they can “clean” the PC. Once they are in, they install real malware, lock your files, or charge you hundreds of dollars for nothing. If a pop-up ever shows you a phone number, or a caller ever asks you to type commands while they watch, close the window and hang up — a real technician does not work that way, and Microsoft will never call you about your PC.
The rule is simple: never run a command because a stranger told you to, and never let a stranger see your screen. If you have already let someone in, our guide to what to do after letting a tech-support scammer connect to your computer walks through disconnecting them, removing their tool, and checking what they changed.
Which Command Actually Scans for Malware?
Only one: Start-MpScan. It is a PowerShell command, not a Command Prompt command, and it works by telling Windows Defender to scan. Open Windows PowerShell as administrator — press the Windows key, type PowerShell, right-click Windows PowerShell, choose Run as administrator — then type the command below and press Enter.
For a quick scan, which checks the folders where malware usually hides:
Start-MpScan -ScanType QuickScan
For a full scan, which checks every file and program on the device:
Start-MpScan -ScanType FullScan
A full scan takes a while — on a large drive, an hour or more — and you should let it finish. When it is done, Defender shows the results in Windows Security, under Virus and threat protection, then Protection history. If it finds something, follow its removal steps. If it finds nothing, you have one scan’s worth of evidence, not a guarantee — and the next section explains why a second opinion matters.
You can also scan a single folder, which is useful when the earlier commands pointed at a suspect location:
Start-MpScan -ScanType CustomScan -ScanPath “C:\Users\YourName\Downloads”
Replace the path with the folder you want to check. The quotes matter — without them, a path with spaces in it will fail.
One more thing the scan does that the other commands do not: it records its results. After the scan, open Windows Security, click Virus and threat protection, then Protection history, and you will see a card for the scan with what it found and what it did. That card is the record to keep — a screenshot of it is useful if you later need to show a technician what Defender found, and when.
What Do I Do After the Scan Finishes?
Read the result, then decide. If Defender found something and removed it, run the scan once more to confirm, then watch the PC for a few days. If the same detection comes back, the problem is not the file — it is whatever puts the file back, and our guide to what to do when Defender keeps finding the same trojan covers exactly that.
If Defender found nothing, get a second opinion before you relax. No single scanner catches everything. Download Malwarebytes Free from malwarebytes.com — the free version is a second-opinion scanner, not a replacement for Defender — install it, and run a scan. If it finds something Defender missed, follow its removal steps, then run the Defender scan again. If both scanners come back clean, and the PC is behaving normally, the odds are in your favour — but keep the habit of checking: a PC that was acting strangely for a reason you never found deserves watching, not forgetting.
If the PC is still showing symptoms after two clean scans — it is slow, pop-ups appear, the browser redirects — the problem may not be malware at all. A failing hard drive, a bad update, or a browser extension can produce the same symptoms. At that point the right step is the general symptom guide: our post on what to do when you think your computer has a virus walks through the symptoms one by one and tells you which ones mean infection and which ones mean something else.
My position is simple: the Command Prompt is a flashlight, not a scanner. Use it to look — a strange connection, a process in the wrong folder, a system file that will not repair — and then hand the verdict to a tool that can actually judge, which is Defender, with a second opinion from Malwarebytes. Anyone who tells you a command can prove your PC is clean is either mistaken or selling you something. The commands show you clues. The scan gives you the answer.
How I Checked This
I did not run these commands against an infected PC, and nothing in this post claims a test I did not run. Here is what I actually did, on 22 November 2026: I opened Microsoft’s own documentation for each command — the netstat page on Microsoft Learn, the tasklist page on Microsoft Learn, the sfc page on Microsoft Learn, and the Start-MpScan page on Microsoft Learn — and read what each command shows and what its options do. I read the Microsoft Q&A forum thread in which a Microsoft answer states, in its own words, that neither the Command Prompt nor PowerShell has built-in malware detection or remediation. I also read this site’s own trojan-recurrence post and tech-support-scam post so this post does not repeat their steps. Where a figure is given, such as the ten-to-twenty-minute time for a full sfc scan, it is the general guidance in Microsoft’s documentation, not a timing I measured myself.
Frequently Asked Questions
Can CMD commands detect a virus on my computer?
No, not by themselves. Microsoft’s own support forum says the Command Prompt and PowerShell have no built-in malware detection or remediation. The commands can show you clues — strange connections, suspicious processes, damaged system files — but only a scanner such as Windows Defender can tell you whether a file is a virus.
What does netstat -ano actually show me?
It shows every connection your PC currently has open, with the foreign address and the process ID that owns each connection. It cannot tell you whether a connection is safe or what data is being sent. A strange-looking address can be a normal server, and a familiar one can be malware in disguise — the list is a clue, not a verdict.
Is sfc /scannow a virus scan?
No. System File Checker checks whether Windows’ own system files are damaged and repairs them from a clean copy. It does not look for viruses and a clean result does not mean your PC is clean. If it cannot repair the files it finds, run DISM /Online /Cleanup-Image /RestoreHealth first, then run sfc again.
How do I know if a process in tasklist is malware?
You cannot tell from the name alone. Check where the process runs from: a real Windows process runs from C:\Windows\System32, while the same name running from a folder in your user profile or a temp folder is a suspect. Use tasklist /v to see the path, note it down, and let a Defender scan judge it — do not delete files by hand.
Can a hidden file shown by attrib be a virus?
It can be, but hidden does not mean malicious — Windows hides thousands of files by default. The command only shows you the attribute. The one case where it is a strong sign is a USB drive that suddenly looks empty: if attrib reveals your files with the hidden attribute set, that is a classic USB-spreading infection, and you should scan the drive before opening anything on it.
What is the one CMD command that actually scans for malware?
There is not one in Command Prompt. The command that scans is Start-MpScan, and it runs in PowerShell, not CMD. Open Windows PowerShell as administrator and type Start-MpScan -ScanType FullScan. It tells Windows Defender to scan — the command itself does not detect anything, Defender does.
Should I trust a caller who asks me to type commands?
No. Tech-support scammers use netstat and tasklist to make normal lists of connections and processes look like proof of infection, then ask you to download their remote-access tool. Microsoft will never call you about your PC. Hang up, close the window, and if you already let someone in, follow our guide to what to do after a tech-support scammer connects.
Sources: Microsoft Learn, “netstat,” https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/netstat; Microsoft Learn, “tasklist,” https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/tasklist; Microsoft Learn, “sfc,” https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sfc; Microsoft Learn, “Start-MpScan,” https://learn.microsoft.com/en-us/powershell/module/defender/start-mpscan; Microsoft Learn forum, Microsoft Q&A answer: “We don’t really have any built-in malware detection or remediation capabilities in either the Windows Command Prompt or the PowerShell Prompt.” All sources checked November 22, 2026.












