> ## Documentation Index
> Fetch the complete documentation index at: https://docs.directgvr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use conditional elevation for updates

> Ask for administrator rights only when an update needs to write to a protected folder.

You can have the launcher ask for elevated privileges only when an update is needed and the install folder is protected, such as `C:\Program Files` on Windows.

> [!NOTE]
>
> This also works on macOS, but we don't recommend running game updates as the root user on a Mac.

## Check the repository for updates

A `repositoryCheck` task decides whether the repository needs installing or updating, and routes the workflow. Here both cases go to the writable check:

```json theme={null}
"updateCheck": {
  "type": "repositoryCheck",
  "repository": "{repositoryName}",
  "catalog": "{repositoryCatalogUrl}",
  "alias": "{repositoryAliasUrl}",
  "title": "{repositoryTitle}",
  "metafile": "{installDirectory}{repositoryMetafile}.json",
  "update": "updateElevatedCheck",
  "install": "updateElevatedCheck",
  "progressWeight": 0
},
```

## Check whether the folder is writable

A `directoryIsWritable` task checks whether the launcher can write to the install folder with its current permissions. Unless the player runs it as administrator, the launcher runs as a regular user.

```json theme={null}
"updateElevatedCheck": {
  "type": "directoryIsWritable",
  "path": "{installDirectory}",
  "recurse": true,
  "writable": "updateActions",
  "notWritable": "updateActionsElevated",
  "progressWeight": 0
},
```

If the folder is writable, such as `c:\Users\Username\Games\`, the launcher updates normally. If it isn't, such as `c:\Program Files (x86)\Games\`, the workflow asks for administrator rights.

## Run the update elevated

A `workflowRun` task with `"elevated": true` runs a task with administrator rights. `start` names the task to run in the existing workflow.

```json theme={null}
"updateActionsElevated": {
  "type": "workflowRun",
  "url": "{ContentUrl}workflow.json",
  "arguments": "{commandLine}",
  "elevated": true,
  "start": "updateActions",
  "progressWeight": 0
},
```

When this task runs, Windows shows a User Account Control prompt asking the player to let the launcher run as administrator. For more about `workflowRun`, see [Tasks](https://docs.directgvr.com/reference/client-workflow-engine/tasks.md).

## Full example

This workflow uses a [unified progress bar](https://docs.directgvr.com/reference/client-workflow-engine/progress.md) for two repositories and only elevates if an update is needed. The `repair` task, which runs when the player clicks **Repair**, also elevates if needed.

```json workflow.json theme={null}
{
  "extendAnalytics": {
    "type": "analytics",
    "keyValuePairs": {
      "os": "{SystemName} {SystemVersion} ({SystemBitness}-bit)",
      "appVersion": "{AppVersion}"
    }
  },
  "loadMacros": {
    "type": "macro",
    "keyValuePairs": {
      "repositoryName": "mygame-{systemShortName}.env.production",
      "repositoryMetafile": "mygame-{systemShortName}",
      "repositoryTitle": "My Game",
      "repositoryName2": "maps.env.production",
      "repositoryMetafile2": "maps",
      "repositoryTitle2": "Maps",
      "repositoryLauncher": "mylauncher.env.production",
      "repositoryAliasUrl": "https://cdn.example.com/aliases.json",
      "repositoryCatalogUrl": "https://cdn.example.com/",
      "executableName-win": "binaries/game.exe",
      "installDirectory": "{ProgramFiles}MyCompany{pathSlash}Games{pathSlash}",
      "selfUpdateDirectory": "{moduleDirectory}"
    }
  },
  "load": {
    "type": "queue",
    "concurrentTasks": 1,
    "actions": [ "extendAnalytics", "loadMacros" ]
  },
  "update": {
    "type": "progress",
    "status": ["UI_CheckingForUpdate", "UI_Done"],
    "taskChainParameter": ["equalTo", "notEqualTo", "start", "missing", "read", "writable", "lessThan", "update"],
    "actions": ["updateCheck", "updateCheck2"],
    "verbose": false
  },
  "updateCheck": {
    "type": "repositoryCheck",
    "repository": "{repositoryName}",
    "catalog": "{repositoryCatalogUrl}",
    "alias": "{repositoryAliasUrl}",
    "title": "{repositoryTitle}",
    "metafile": "{installDirectory}{repositoryMetafile}.json",
    "update": "updateElevatedCheck",
    "install": "updateElevatedCheck",
    "progressWeight": 0
  },
  "updateCheck2": {
    "type": "repositoryCheck",
    "repository": "{repositoryName2}",
    "catalog": "{repositoryCatalogUrl}",
    "alias": "{repositoryAliasUrl}",
    "title": "{repositoryTitle2}",
    "metafile": "{installDirectory}{repositoryMetafile2}.json",
    "update": "updateElevatedCheck",
    "install": "updateElevatedCheck",
    "progressWeight": 0
  },
  "updateElevatedCheck": {
    "type": "directoryIsWritable",
    "path": "{installDirectory}",
    "recurse": true,
    "writable": "updateActions",
    "notWritable": "updateActionsElevated",
    "progressWeight": 0
  },
  "updateActionsElevated": {
    "type": "workflowRun",
    "url": "{ContentUrl}workflow.json",
    "arguments": "{commandLine}",
    "elevated": true,
    "start": "updateActions",
    "progressWeight": 0
  },
  "updateActions": {
    "type": "queue",
    "concurrentTasks": 1,
    "actions": [ "updateSync", "updateSync2" ],
    "progressWeight": 0
  },
  "updateSync": {
    "type": "repositorySync",
    "status": "UI_Updating",
    "repository": "{repositoryName}",
    "catalog": "{repositoryCatalogUrl}",
    "alias": "{repositoryAliasUrl}",
    "title": "{repositoryTitle}",
    "metafile": "{installDirectory}{repositoryMetafile}.json",
    "local": { "type": "file", "path": "{installDirectory}" },
    "backup": { "type": "filePiece", "path": "{installDirectory}Backup" }
  },
  "updateSync2": {
    "type": "repositorySync",
    "status": "UI_Updating",
    "repository": "{repositoryName2}",
    "catalog": "{repositoryCatalogUrl}",
    "alias": "{repositoryAliasUrl}",
    "title": "{repositoryTitle2}",
    "metafile": "{installDirectory}{repositoryMetafile2}.json",
    "local": { "type": "file", "path": "{installDirectory}" },
    "backup": { "type": "filePiece", "path": "{installDirectory}Backup" }
  },
  "repair": {
    "type": "progress",
    "status": ["UI_Repairing", "UI_Done"],
    "taskChainParameter": ["equalTo", "notEqualTo", "start", "missing", "read", "writable", "lessThan", "update"],
    "actions": ["repairElevatedCheck"],
    "verbose": false
  },
  "repairElevatedCheck": {
    "type": "directoryIsWritable",
    "path": "{installDirectory}",
    "recurse": true,
    "writable": "repairActions",
    "notWritable": "repairActionsElevated",
    "progressWeight": 0
  },
  "repairActionsElevated": {
    "type": "workflowRun",
    "url": "{ContentUrl}workflow.json",
    "arguments": "{commandLine}",
    "elevated": true,
    "start": "repairActions",
    "progressWeight": 0
  },
  "repairActions": {
    "type": "queue",
    "concurrentTasks": 1,
    "actions": [ "repairSync", "repairSync2" ],
    "progressWeight": 0
  },
  "repairSync": {
    "type": "repositorySync",
    "repository": "{repositoryName}",
    "catalog": "{repositoryCatalogUrl}",
    "alias": "{repositoryAliasUrl}",
    "title": "{repositoryTitle}",
    "metafile": "{installDirectory}{repositoryMetafile}.json",
    "local": { "type": "file", "path": "{installDirectory}" },
    "repair": true
  },
  "repairSync2": {
    "type": "repositorySync",
    "repository": "{repositoryName2}",
    "catalog": "{repositoryCatalogUrl}",
    "alias": "{repositoryAliasUrl}",
    "title": "{repositoryTitle2}",
    "metafile": "{installDirectory}{repositoryMetafile2}.json",
    "local": { "type": "file", "path": "{installDirectory}" },
    "repair": true
  },
  "launch": {
    "type": "launch",
    "path": "{installDirectory}{executableName-{systemShortName}}",
    "workingDirectory": "{installDirectory}",
    "elevationRights": "user",
    "successCode": 0,
    "waitForExit": true
  },
  "start": {
    "type": "queue",
    "concurrentTasks": 1,
    "actions": [ "update" ]
  }
}
```

## Related

* [Configure the launcher to download your repositories](https://docs.directgvr.com/launcher-design/download-repositories.md)
* [Set up launcher self-update](https://docs.directgvr.com/launcher-design/self-update.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.