Cyber security

Hacked? Commands to run in Windows CMD

Open Command Prompt as Administrator (search “cmd”, right-click, Run as administrator) and work through these steps.

First: use a different, safe device to change your email, banking and M-Pesa passwords and turn on two-step verification. Don't log in to important accounts on the affected computer until it's clean.

1. See what is connecting to the internet

Lists all active connections and the process ID (PID) using them. Look for unknown foreign addresses.

netstat -ano

Shows running programs. Match a suspicious PID from netstat to a program name.

tasklist

Force-stops a suspicious program (replace 1234 with the PID).

taskkill /PID 1234 /F

2. Cut off an attacker

Disconnects the computer from the network immediately.

ipconfig /release

Clears cached website addresses that malware may have changed.

ipconfig /flushdns

Makes sure Windows Firewall is turned on for all networks.

netsh advfirewall set allprofiles state on

3. Check for unknown accounts and startup programs

Lists all user accounts. Look for accounts you did not create.

net user

Shows who has admin rights.

net localgroup administrators

Disables an unknown account (replace the name).

net user SuspiciousName /active:no

Lists programs that start automatically with Windows.

wmic startup get caption,command

Lists scheduled tasks — malware often hides here.

schtasks /query /fo LIST /v

4. Scan and repair

Runs a full Microsoft Defender malware scan.

"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2

Finds and repairs damaged Windows system files.

sfc /scannow

Repairs the Windows image if sfc cannot fix everything.

DISM /Online /Cleanup-Image /RestoreHealth

Shows the hosts file. Extra lines can redirect you to fake sites.

type C:\Windows\System32\drivers\etc\hosts

Still unsure? Try the auto-help assistant or see our Lumex Digital cyber security services.