# $cs.Service_Stop

> Stops the named service and waits up to maxTimeout milliseconds for it to reach the Stopped state.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-service-stop/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Stops the named service and waits up to `maxTimeout` milliseconds for it to reach the Stopped state. Unlike `$cs.Service_Start`, if the service doesn't exist at all this returns silently with no error — it does not throw.

### Syntax

$cs.Service_Stop(string servicename, uint maxTimeout = 60000)

### Parameters

#### servicename (String)

Name of the service to stop.

#### maxTimeout (UInt32)

Maximum time to wait, in milliseconds, for the service to reach the Stopped state. Defaults to `60000` (60 seconds).

### Return value

None.

### Example

**PowerShell**

Check the service exists before stopping it:

```powershell
if ($cs.Service_Exist("gupdate"))
{
  $cs.Job_WriteLog("Stopping gupdate service")
  $cs.Service_Stop("gupdate", 30000)
}
```

Stop a service before replacing its binary during an in-place upgrade, then start it again afterward:

```powershell
$cs.Job_WriteLog("Stopping MyAppService before replacing binaries")
$cs.Service_Stop("MyAppService", 60000)
Copy-Item -Path "$global:Packageroot\MyAppService.exe" -Destination "$env:ProgramFiles\MyApp\MyAppService.exe" -Force
$cs.Job_WriteLog("Starting MyAppService with updated binary")
$cs.Service_Start("MyAppService")
```

Call it defensively during uninstall without first checking existence — it silently does nothing if the service was never installed:

```powershell
$cs.Job_WriteLog("Ensuring MyAppService is stopped before uninstall, in case it exists")
$cs.Service_Stop("MyAppService")
```

### Related functions

[$cs.Service_Exist](/capainstaller/powerpacks/cs-service-exist/) [$cs.Service_Start](/capainstaller/powerpacks/cs-service-start/)
