# $cs.Sys_WaitForProcessToExist

> Waits for a process to appear/start, checking every IntervalSec seconds up to a total of MaxWaitSec seconds.

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

### Description

Waits for a process to appear/start, checking every `IntervalSec` seconds up to a total of `MaxWaitSec` seconds. If the process already exists, returns immediately. Same caveat as `$cs.Sys_WaitForProcess`: this always returns silently, with no indication of whether the process actually appeared or the timeout was reached — check `$cs.Sys_ExistProcess(...)` afterward if you need to know.

### Syntax

$cs.Sys_WaitForProcessToExist(string processname, int MaxWaitSec, int IntervalSec)

### Parameters

#### processname (String)

Name of the process to wait for.

#### MaxWaitSec (Integer)

Maximum total number of seconds to wait for the process to appear.

#### IntervalSec (Integer)

Number of seconds to sleep between each check.

### Return value

None.

### Example

**PowerShell**

Wait for a spawned process to actually start before acting on it:

```powershell
$cs.Job_WriteLog("Waiting up to 30 seconds for clickshare_native.exe to start")
$cs.Sys_WaitForProcessToExist("clickshare_native.exe", 30, 1)
if ($cs.Sys_ExistProcess("clickshare_native.exe"))
{
  $cs.Sys_KillProcess("clickshare_native.exe")
}
```

Launch a setup executable asynchronously, wait for its actual process to appear, then wait for it to finish:

```powershell
Start-Process -FilePath "$global:Packageroot\setup.exe" -ArgumentList "/silent"
$cs.Job_WriteLog("Waiting up to 20 seconds for setup.exe to start")
$cs.Sys_WaitForProcessToExist("setup.exe", 20, 1)
if ($cs.Sys_ExistProcess("setup.exe"))
{
  $cs.Job_WriteLog("setup.exe started, waiting for it to complete")
  $cs.Sys_WaitForProcess("setup.exe", 600, 5)
}
else
{
  $cs.Job_WriteLog("setup.exe never started within the timeout")
}
```

### Related functions

[$cs.Sys_ExistProcess](/capainstaller/powerpacks/cs-sys-existprocess/) [$cs.Sys_WaitForProcess](/capainstaller/powerpacks/cs-sys-waitforprocess/) [$cs.Sys_KillProcess](/capainstaller/powerpacks/cs-sys-killprocess/)
