# Windows Requirement Script Examples

Requirement scripts run on client devices at each tickle interval, 2 minutes by default, to check whether installation conditions are met. A script can check for a file, registry key, service, or process before allowing Fileset activation. Common uses include:

1. Block redundant installations if the app is already present or
2. Ensure prerequisites are present or
3. Enforce a particular installation order.

If a requirement script returns any exit code other than 0, such as 1 or -1, FileWave treats it as a failure and reports *Requirements Failure: Script* in the *Client Info* window and Fileset Report. The Fileset contents will not download or install until all requirement scripts return 0. To check multiple conditions, add multiple requirement scripts.

![qfNh1KpcKOQ3Hvjw-embedded-image-uhfx0p7y.png](https://kb.filewave.com/uploads/images/gallery/2023-07/qfNh1KpcKOQ3Hvjw-embedded-image-uhfx0p7y.png)

The examples below are Windows requirement scripts you can adapt. If you need the opposite condition, swap the exit codes in the example.

***Install if registry key present***

```
::Replace HKLM\path\to\registry\key with the actual path to the registry key, e.g. HKLM\SOFTWARE\Macromedia\FlashPlayer
 
reg query "HKLM\path\to\registry\key"
if %ERRORLEVEL% EQU 0 (
    exit 0
) else (
    exit 1
)
```

***Install if registry value present***

```
::Replace HKLM\path\to\registry\key with the actual path to the registry key containing your value, e.g. HKLM\SOFTWARE\Macromedia\FlashPlayer
::Replace <value> with the actual name of the value, e.g. CurrentVersion in this example
 
reg query "HKLM\path\to\registry\key" /v <value>
if %ERRORLEVEL% EQU 0 (
    exit 0
) else (
    exit 1
)
```

***Install if file or folder present***

```
::Replace <drive>:\path\to\file\or\folder with the actual path to the file or folder, e.g. %ProgramFiles(x86)%\Mozilla Firefox\firefox.exe
 
if exist "<drive>:\path\to\file\or\folder" (
    exit 0
) else (
    exit 1
)
```

***Install if application present in Programs &amp; Features***

```
::Replace <AppName> with the name of your app, e.g. Adobe Acrobat Reader DC
::Be as specific as possible because partial app names may provide a match when you don't necessarily want it to, e.g. Adobe will match both Adobe Acrobat Reader DC and Adobe Flash
 
reg export HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall %temp%\applist1.txt
reg export HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall %temp%\applist2.txt
copy %temp%\applist1.txt + %temp%\applist2.txt %temp%\applisttemp.txt
find "DisplayName" %temp%\applisttemp.txt > %temp%\applist.txt
 
find "<AppName>" %temp%\applist.txt
if %ERRORLEVEL% EQU 0 (
    del %temp%\applist*
    exit 0
) else (
    del %temp%\applist*
    exit 1
)
```

***Install if service present***

```
::Replace <service> with the name of your service from the Services control panel, e.g. Adobe Acrobat Update Service
::Be as specific as possible because partial service names may provide a match when you don't necessarily want it to, e.g. FileWave will match both FileWave Client and FileWave UltraVNC Server
 
sc query | find "DISPLAY_NAME" | find "<service>"
if %ERRORLEVEL% EQU 0 (
    exit 0
) else (
    exit 1
)
```

***Install if process present***

```
::Replace <process> with the name of your process, e.g. notepad.exe
 
tasklist /FI "IMAGENAME eq <process>" 2>NUL | find /I /N "<process>"
if %ERRORLEVEL% EQU 0 (
    exit 0
) else (
    exit 1
)
```

If you find that you need to delete a requirement script for any reason, right-click that script and choose *Reveal in Fileset*. That will open the *Fileset Contents* window with the script file highlighted. Click the *Delete* icon in the toolbar to delete your script.

![2q00MQgiNYbRhaIb-embedded-image-dhd0mgqw.png](https://kb.filewave.com/uploads/images/gallery/2023-07/2q00MQgiNYbRhaIb-embedded-image-dhd0mgqw.png) ![4m0mqzIZnZIGnYYB-embedded-image-b0rs0i3m.png](https://kb.filewave.com/uploads/images/gallery/2023-07/4m0mqzIZnZIGnYYB-embedded-image-b0rs0i3m.png)

Test requirement scripts locally before adding them to a Fileset. These examples provide building blocks for Windows Filesets that should install only when specific local conditions are true.