How to check which port is used by a particular process/application on Windows

To find the process ID (PID) of the application, we need to run following command:

tasklist | findstr '<application/process name>

This will display all processes running on machine, where process name contains <application/process name> value. Result of above command includes PID – we will use this in next step.

Next, we run below command to find actual port number used by the process:

netstat -ano | findstr <PID>

This command lists all ports used by process.

Windows command line aliases

In this article I’ll walk through creating alias in Windows command line. I will create alias named “subl” for launching Sublime Text 3 editor from command line.

For this purpose, doskey command is particularly useful.

Sublime Text 3 is installed in default folder on my PC, so running below command will do the trick:

doskey subl="C:\Program Files\Sublime Text 3\sublime_text.exe"

Now I can type

subl

in command prompt and system starts Sublime Text 3 editor.

There is one little catch here though. Even if I type

subl C:\tmp\file.txt

Sublime always opens new blank document.

In order to be able to pass parameter into the alias, doskey command needs to be altered slightly:

doskey subl="C:\Program Files\Sublime Text 3\sublime_text.exe" $*

Adding “$*” at the end allows the alias to accept zero, one, or more args.

I can now type

subl C:\tmp\file.txt

and Sublime happily loads correct file.

Gotcha!

While using this alias, I discovered one very annoying thing: aliases disappear when console is restarted. Doskey command needs to be called again.

There is a way to automate loading Doskey macros (loads of information on this on google), but it requires modifying Windows registry, which I did not want.

Instead I found easier solution:

I created very simple batch file called subl.bat:

@ECHO OFF

START "" "C:\Program Files\Sublime Text 3\sublime_text.exe" %1

And moved it to location listed in system PATH variable, i.e. %USERPROFILE%

Now calling

subl \tmp\path.txt

Launches new instance of Sublime Text even after restarting console.

Voila!