# $cs.Service_Exist

> Checks whether a service with the given name is registered on the system, by looking for its key under the SYSTEM\CurrentControlSet\Services registry path.

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

### Description

Checks whether a service with the given name is registered on the system, by looking for its key under the `SYSTEM\CurrentControlSet\Services` registry path.

### Syntax

$cs.Service_Exist(string servicename)

### Parameters

#### servicename (String)

Name of the service to check for.

### Return value

Boolean. `$true` if a registry key for the service is found, otherwise `$false`.

### Example

**PowerShell**

Check whether a service exists before stopping it:

```powershell
if ($cs.Service_Exist("gupdate"))
{
  $cs.Job_WriteLog("gupdate service found, stopping it")
  $cs.Service_Stop("gupdate")
}
```

Verify a dependency service is registered before attempting to start it, and abort the install if it's missing:

```powershell
if (!$cs.Service_Exist("MySqlServerService"))
{
  throw "Required dependency service MySqlServerService is not installed"
}
$cs.Job_WriteLog("Dependency service found, starting it")
$cs.Service_Start("MySqlServerService")
```

Only attempt cleanup of a service during uninstall if it was actually installed by this package:

```powershell
if ($cs.Service_Exist("MyAppBackgroundService"))
{
  $cs.Job_WriteLog("Removing MyAppBackgroundService")
  $cs.Service_Stop("MyAppBackgroundService")
  Start-Process "sc.exe" -ArgumentList "delete MyAppBackgroundService" -Wait
}
else
{
  $cs.Job_WriteLog("MyAppBackgroundService not present, nothing to remove")
}
```

### Related functions

[$cs.Service_Start](/capainstaller/powerpacks/cs-service-start/) [$cs.Service_Stop](/capainstaller/powerpacks/cs-service-stop/)
