Wednesday, July 21, 2010

How to know what process is using which port in windows

I believe this is going to be a very helpful post to most of the readers. So many times I need to know about this. This is a great tip to resolve so many problems. So, it is one of my hot tips for identifying the problems.

We usually install third party software like Skype, TeamViewer etc. in the windows OS, then they will default take some port numbers available. Then there are chances they will create some problem as explained below. [This is why we need to take care of installing software on the servers or production machines. We should install if and only if we really need them. :)] Below is the complete scenario.
  1. I have service 1 which is not running right now and I have assigned port number 80 for the service. 
  2. I have installed the third party software and assigned port number 80 or by default it has taken port number 80 without knowing me. 
  3. Now, there is a need to start service 1 in my system and use it.
  4. But, it never starts. Because the same port number is already allocated to something else process... So, in this situation we can't find the problem very easily. 
We need to do some investigation here. Below is the process we need to follow. First we need to find out what all processes using which port. And then find out the result process list and take further action.

Finding which process is using which port number:
  1. Open command prompt by going to Windows --> Run or [Start + R]. 
  2. Type cmd in there and hit enter.
  3. Now, you came up with command prompt window.
  4. Type the syntax exactly as shown. netstat -aon | findstr 0.0:80
In the above syntax a means active, o means include process ID's and n means the port numbers in the result. findstr is the attribute in the command to find out only the strings which has the string given. It only finds which has the given string matched to shorten the result.

Below is the sample output I got when I used the command.

The result order is, TCP protocol,  port, listening status, process id. The last column is the process id.

Find out what is the process from process id:
Now, it is the time to find out what is the process  which has the ID 4?
To know the process and their ids we have two options. Either go to the windows task manager  --> services tab and you can see all the processes with their process ids or from command prompt.
Use the command tasklist | findstr 4. It will list all the processes which has 4 in it as shown below. See all and check everything and find out what you need.

Hope this post helps to solve the problems. Enjoy the nice series of posts.

7 comments:

  1. Thanks for the comment. That really not matters. They are just options. It's not command. We can give any order.

    -Praveen

    ReplyDelete
  2. Does it affect the registry? If so, in which way?

    ReplyDelete
  3. Great Post
    Thank you very much praveen...

    ReplyDelete
  4. Thanks, it was helpful

    ReplyDelete