# Getting Started with VB Scripting

> The skeleton every VBScript package starts from, and the conventions used across the VB Scripting Library reference.

Source: https://docs.capaone.com/capainstaller/vb-scripting-library/getting-started-with-vb-scripting/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

This page explains the skeleton that every VBScript package starts from, and the conventions used throughout the [VB Scripting Library](/capainstaller/vb-scripting-library/) reference. Read this first if you are about to write your first package — the function reference assumes you already know this.

:::danger[VBScript is being phased out]
Microsoft has announced that [VBScript is deprecated and being removed from Windows](https://techcommunity.microsoft.com/blog/windows-itpro-blog/vbscript-deprecation-timelines-and-next-steps/4148301). Existing VBScript packages will keep working for now, but **new packages should not be built in VBScript**.

Build new packages as a [PowerPack](/capainstaller/powerpacks/) instead, or as a Custom App/script in CapaOne, tested there and then exported for CapaInstaller — CapaOne lets you export the result as a zip file that can be imported directly into the CapaInstaller Console.
:::

## How a package is created

A VBScript package is not written from scratch — it is generated by [Package Creator](/capainstaller/package-creator/): right-click *Packages* → *Create package*, pick a template (Basic, Generic Installer, MSI, InstallShield, App-V, Thinstall, ...), fill in the wizard, and click *Generate*. This produces the `.cis` script(s) for the package — typically an install script, an uninstall script, and (if the package needs one) a user setup script — already wired up with the skeleton below. You then edit the generated script to add your own install/uninstall logic; you don't write the skeleton yourself.

## The standard skeleton

Every generated script — regardless of which template you picked — follows the same shape. Using a Basic install script as an example:

**VBScript**

```vb
Dim bStatus

Private Function IncludeScript(sScriptFile)
  '... (generated boilerplate that loads the script; never edit this function)
End Function

Function Install()
Dim bStatus
'Begin
  bStatus=True
  ' <- your install logic goes here
  Install=bStatus
End Function

Function CustomPreInstall()
Dim bStatus
'Begin
  bStatus=True
  ' <- optional: anything that must run before Install()
  CustomPreInstall=bStatus
End Function

Function CustomPostInstall()
Dim bStatus
'Begin
  bStatus=True
  ' <- optional: anything that must run after Install()
  CustomPostInstall=bStatus
End Function

'Begin main
  bStatus=True
  If bStatus Then bStatus=IncludeScript("customlib.cis")
  If bStatus Then bStatus=IncludeLibrary("capalib.cin")

  If bStatus Then bStatus=Job_SetPlatform("CDM")
  If bStatus Then bStatus=Job_Start("WS","Clean VB","v1","Clean VB.Log","INSTALL")
  If bStatus Then bStatus=Job_AttendedInstallation()
  If bStatus Then bStatus=Job_SetLanguage("OS")
  If bStatus Then bStatus=Sys_GetFreeDiskSpace("C:",10)
  If bStatus Then bStatus=CDM_DefineEndUserCancellation(9999,99991231,"ALWAYS")
  If bStatus Then bStatus=Job_SetStartTime()
  If bStatus Then bStatus=CustomInit("Clean VB")
  If bStatus Then bStatus=CDM_DownloadPackageBeforeInstall(25,gsTempDir)
  If bStatus Then bStatus=CustomPreInstall()
  If bStatus Then bStatus=Job_InstallationStart("Clean VB","5",10,2)
  If bStatus Then bStatus=Install()
  If bStatus Then bStatus=CustomPostInstall()
  If bStatus Then bStatus=CDM_RemoveLocalPackage(gsTempDir)
  bStatus=Job_InstallationCompleted("Clean VB",bStatus)
  Job_End(bStatus)
'End Main
```

:::caution
Don't change the order of the calls in `'Begin main`, and don't remove any of them — the platform expects this exact sequence, and a package can fail in confusing ways if it's reordered or a step is missing. What you *can* change is:
- the logic **inside** `Install()` / `Uninstall()` / `CustomPreInstall()` / `CustomPostInstall()`, and
- adding entirely new custom functions of your own, called from inside those four hooks (or from `'Begin main` itself, if you need a new step).
:::

### What each step does

| Step | Purpose |
|---|---|
| `IncludeScript("customlib.cis")` / `IncludeLibrary("capalib.cin")` | Loads the customer-specific module and the CapaInstaller Scripting Library itself. Generated as-is — never edit. |
| `Job_SetPlatform("CDM")` | Always `"CDM"` for a normal CapaInstaller package. Leave it as generated. |
| [Job_Start](/capainstaller/vb-scripting-library/job-functions/job-start/) | Initializes the job: sets up logging, and everything downstream (including the `gs`/`gb` globals in [Variables](/capainstaller/vb-scripting-library/addendum/variables/)) depends on this having run first. |
| `Job_AttendedInstallation()` / `Job_SilentInstallation()` | Declares whether this run shows UI to the end-user or runs silently — which one is generated depends on the package type/template you picked. |
| `Job_SetLanguage("OS")` | Sets the language used for any built-in end-user messages. |
| [Sys_GetFreeDiskSpace](/capainstaller/vb-scripting-library/system-functions/sys-getfreediskspace/) | Aborts the install early if there isn't enough disk space. |
| `CDM_DefineEndUserCancellation`, `CDM_DownloadPackageBeforeInstall`, `CDM_RemoveLocalPackage` | Standard bookkeeping steps generated by Package Creator (end-user cancellation window, staging the package locally before install, cleaning up the local copy afterward). Treat these as boilerplate — leave them as generated rather than tuning their parameters by hand. |
| `Job_SetStartTime()` | Marks the start time used for install duration reporting. |
| `CustomInit(sPackageName)` | A hook from `customlib.cis`, not the Scripting Library itself. Always takes the package's name as its only parameter. |
| `CustomPreInstall()` / `CustomPostInstall()` | Your two customization hooks — add anything that needs to happen immediately before/after the main install logic. |
| `Job_InstallationStart(...)` | Marks the point where the actual install work begins (used for progress reporting). |
| `Install()` / `Uninstall()` | The function you actually edit: this is where your package's real logic goes. |
| [Job_ActivateUserSetup](/capainstaller/vb-scripting-library/job-functions/job-activateusersetup/) / [Job_RemoveUserSetup](/capainstaller/vb-scripting-library/job-functions/job-removeusersetup/) | Only present if the package has a user setup script — registers/removes the per-user part of the install. |
| [Job_InstallationCompleted](/capainstaller/vb-scripting-library/job-functions/job-installationcompleted/) | Reports the overall install result. |
| [Job_End](/capainstaller/vb-scripting-library/job-functions/job-end/) | Always the last call. The `bStatus` value passed here is what the CapaInstaller Console shows as the package's success/failure status. |

## The `bStatus` convention

Almost every line in a CapaInstaller script looks like this:

```vb
If bStatus Then bStatus=SomeFunction(...)
```

Every Scripting Library function returns `True` or `False` depending on whether it succeeded. This line means: *"only run `SomeFunction` if everything so far has succeeded, and record whether it succeeded too."* Once `bStatus` becomes `False`, every subsequent `If bStatus Then ...` line is skipped — this is a manual short-circuit, not a language feature, so it has to be written out on every single line. Whatever `bStatus` holds when it reaches `Job_End(bStatus)` at the very end is what determines whether the CapaInstaller Console marks the package as succeeded or failed.

## The `gbValue`/`gsValue` convention

Many functions don't return their result directly — instead they return `True`/`False` for "did this step succeed," and put the actual result in the global `gbValue` (Boolean) or `gsValue` (String), which you read immediately afterward:

```vb
If bStatus Then bStatus=Sys_GetFreeDiskSpace("C:",10)
' the disk-space check's own result is now in gbValue, not in bStatus
```

This is the same pattern used throughout the Library (see [Variables](/capainstaller/vb-scripting-library/addendum/variables/) for the full list of `gs`/`gb`/`gi` globals populated this way).

## See also

- [Scripting Guidelines](/capainstaller/vb-scripting-library/scripting-guidelines/)
- [Package Creator](/capainstaller/package-creator/)
- [Constants](/capainstaller/vb-scripting-library/addendum/constants/), [Package Property](/capainstaller/vb-scripting-library/addendum/package-property/), [Variables](/capainstaller/vb-scripting-library/addendum/variables/)
- [Using passwords in CapaInstaller VB Scripting Library](/capainstaller/vb-scripting-library/using-passwords-in-capainstaller-vb-scripting-library/)
