3

I've coded a custom windows service that listens on TCP port 80 but when I try to install it on a Windows Server 2003 machine it fails to start because some other service is already listening on that port. So far I've disabled the IIS Admin service and the HTTP SSL service but no luck.

When I run netstat -a -n -o | findstr 0.0:80 it gives me the process id 4 as the culprit, but when I look at the running processes that process id points to the "System" process.

What can I do to get the System process to stop listening on port 80 and get my service to listen instead?

P.S. I should point out that the service runs fine if I install it on my Windows XP or Windows 7 development boxes. Also, I should specify that this has nothing to do with it being a service. I've tried starting a regular application that attempts to bind to port 80 on the Windows Server 2003 with the same outcome - it fails because another application is already bound to that port.

1

2 Answers 2

2

You want to stop the "World Wide Web Publishing Service".

By the way, the reason the port is actually opened by the 'System' process is because Windows Server 2003 moved parts of IIS into the kernel (specifically in the http.sys driver). This is so that things like static files can be served completely from the kernel (where the TCP/IP stack and filesystem drivers run) without a user-mode switch and provides better performance.

1
  • 1
    Don't forget to flip it off Automatic. Manual might be better if you want your service to work the next time you reboot. Commented May 13, 2010 at 1:22
2

Thanks to some more digging I was able to find a solution to this problem. I was able to find the solution in part because of information provided by @codeka's answer.

To summarize, because Windows Server 2003 introduced a kernel mode driver (http.sys) to handle HTTP requests, I had to download a utility called HttpCfg.exe which comes in the Windows XP Support Tools and use it to instruct http.sys to stop listening for HTTP requests on port 80.

The command to do that was:

httpcfg.exe delete iplisten -i 0.0.0.0:80

After running that command, I used the query action to check that the address was indeed removed

httpcfg.exe query iplisten

And finally, I had to reboot the machine for the changes to take effect. After that I was able to create TCP sockets and bind to port 80.

As a side note, none of the other methods worked (i.e. disabling IIS Admin service, or the World Wide Web Publishing service, or the HTTP SSL service)

NOTE

Of course, the answer strictly refers to how to turn of the built-in mechanism available in Windows for processing HTTP requests via the kernel. It should be noted however that the kernel seems to provide a more efficient way to process HTTP requests than can be achieved in user mode. There are APIs available to leverage http.sys (kernel mode) HTTP processing of requests and I recommend exploring those if that's an option (i.e. unless you're just trying to run a service that's already built)

3
  • Windows Server 2008 doesn't have the program httpcfg.exe, how can achieve the same result on Windows Server 2008 ?
    – aleroot
    Commented Oct 14, 2011 at 15:20
  • @aleroot - the program httpcfg.exe doesn't come in Windows Server 2003 either. As my answer suggests, I had to download it from a windows XP Support Tools package. I don't know if it will be compatible with Server 2008 though. Commented Oct 21, 2011 at 16:18
  • for Win2008r2, use the netsh utility to add your server to the http.sys system, as long as you have different urls, it can serve both servers on port 80. I think you want this: add urlacl url=http://+:80/MyUri user=DOMAIN\user
    – gbjbaanb
    Commented Jan 27, 2012 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .