Ports 1
-1024
, by default, require administrative access. Otherwise you get error code 5 (ACCESS_DENIED
). If you attempt to bind to a port above 1024, e.g.:
http://localhost:8080/
it will work for non-admin users. In your case you tried to listen on port 80
, which HttpServer API limits to administrators.
Everything in Windows is controlled by Access Control Lists (ACLs); this includes the listen ports allowed when using HttpServer. You can display the current ACLs used by http by running:
>netsh http show urlacl
If you do that, you'll see a lot of ACLs already defined by various systems.
Windows Communication Foundation
One ACL entry is particularly interesting:
Reserved URL : http://+:80/Temporary_Listen_Addresses/
User: \Everyone
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;WD)
Everyone is granted the right to listen on port 80
, as long as you live off of:
/Temporary_Listen_Addresses/
This url is used by Windows Communication Foundation (WCF), which normally constructs a URL of the form:
http://+:80/Temporary_Listen_Addresses/{random-guid}/
It also means, if you really want port 80, you can listen with your own, for example:
http://localhost:80/Temporary_Listen_Addresses/64E3DCC6-FE47-4A86-87F4-48D2E1B44AE9/
As long as nobody is already using port 80 (i'm looking at your Skype!), you'll get it.
WinSock listening sockets do not require admin
While the HttpServer API has ACLs controlling access to ports below 1024
, it should be noted that the WinSock API has no restriction.
If you want to use WinSock to open a listening socket on port 80
, you do not need to be an administrator. It is only the Http
api that has the ACL.