Skip to content

Instantly share code, notes, and snippets.

@nexusstar
Last active April 30, 2018 12:25
Show Gist options
  • Save nexusstar/be6055f8a6086a2fd932390d154844c7 to your computer and use it in GitHub Desktop.
Save nexusstar/be6055f8a6086a2fd932390d154844c7 to your computer and use it in GitHub Desktop.
Get PID and Image Name Windows

Get PID and Image Name

Use only one command:

for /f "tokens=5" %a in ('netstat -aon ^| findstr 9000') do tasklist /FI "PID eq %a"

where 9000 should be replaced by your port number.

The output will contain something like this:

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
java.exe                      5312 Services                   0    130,768 K
Explanation:

it iterates through every line from the output of the following command:

netstat -aon | findstr 9000

from every line, the PID (%a - the name is not important here) is extracted (PID is the 5th element in that line) and passed to the following command

tasklist /FI "PID eq 5312"

SQL Server Reporting Services (ReportServer)
Web Deployment Agent Service (MsDepSvc)
BranchCache (PeerDistSvc)
Sync Share Service (SyncShareSvc)
World Wide Web Publishing Service (W3SVC)
Internet Information Server (WAS, IISADMIN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment