0

After running a netstat command and discovering that a system service was listening at port 80, I checked through the Internet and found this solution:

Port 80 is being used by SYSTEM (PID 4), what is that?

I ran

sc stop w3svc

then

sc config w3svc start= disabled 

but the sc config w3svc start= disabled command returned this error

Set-Content : A position parameter cannot be found that accepts argument 'start='.

Basically, it is an invalid argument but almost every solution I have seen on this platform is suggesting this exact command line for stopping and disabling the service.

Can anyone help because I don't want to disable the whole HTTP service from the registry, I wouldn't mind being guided on how to probably bind this service to another port because I need another application that needs to use this port 80.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Abidemi
  • 3
  • 1
  • 2

2 Answers2

3

PowerShell has it's own cmdlet's for managing Windows Services so it's better to use those than calling a commandline tool from PowerShell. Using the commandlets gives you much better error handling.

Set-Service -Name w3svc -StartupType Disabled

See Set-Service.

If you want to change the port that IIS is listening to from port 80 to something else you can do this via IIS Manager or with PowerShell (requires Import-Module WebAdministration). Here is an example to change the port for the Default Web Site from port 80 to 8080:

Set-WebBinding -Name 'Default Web Site' -BindingInformation "*:80:" -PropertyName Port -Value 8080
Remko
  • 7,214
  • 2
  • 32
  • 52
  • Thank you for this answer. I did ran the command and it executed, but i did a netstat -aon | findstr 0.0:80 and noticed that it is still being listening to thesame PID 4 (which happen to be label system on the services list). I checked the file location and was redirected to ntkrnl, meaning the port is being used by both the kernel and system. Is there a way I can bind the ntkrnl.exe to another port without ruining the OS or something. I have an access control app that uses port 80 by the default and the technical support guy from want me to reinstall the whole OS just because of it. – Abidemi Mar 21 '19 at 11:00
  • You need to identify what is listening on this port, might be a website other than Default Website or even a process different than IIS. Maybe this helps: https://www.remkoweijnen.nl/blog/2012/01/02/system-process-pid-4-is-listening-on-port-80/ – Remko Mar 21 '19 at 11:18
2

In Powershell, sc is an alias to Set-Content, and aliases have a higher precedence than paths. You have two options:

  1. Use cmd instead of Powershell to execute the command

  2. Use sc.exe instead of sc: Your command would become sc.exe config w3svc start= disabled

arco444
  • 22,002
  • 12
  • 63
  • 67