Abidemi
Abidemi

Reputation: 3

How Do I Start A Service Disabled in PowerShell

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.

Upvotes: 0

Views: 4432

Answers (2)

Remko
Remko

Reputation: 7340

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

Upvotes: 3

arco444
arco444

Reputation: 22831

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

Upvotes: 2

Related Questions