I have the following scenario from one of our clients:
and I thought it might be useful to share a solution to this with you all, considering this can be a more common scenario than I initially thought.I have a checkbox that I would like to set based on a value from a JSON file on disk that is not installed by my package.
There are many ways in which we can achieve such feat, but the one we'll explore today will be a PowerShell script.
Of course, for this, it would be ideal for the location of the JSON file to be known beforehand so that wen can go straight to that without having to do a search for the file.
Assume we have the following JSON file:
Code: Select all
$env:ProgramData\MyCompany\MyApp\config.jsonCode: Select all
{
"server": {
"url": "https://example.com/api",
"name": "testName",
"version": "1.0.1"
}
}Here is a little PowerShell script that does just that:
Code: Select all
$json = Get-Content "$env:ProgramData\MyCompany\MyApp\config.json" -Raw -ErrorAction SilentlyContinue | ConvertFrom-Json
$value = $json.server.url # <-- the value you want
if ($value) { AI_SetMsiProperty SERVER_URL $value } # <-- if the value exists, set a property to that valueAnd that our dialog containing the CheckBox control is "NewDialog_1".
Here's how the Checkbox is configured:
In order to influence the state of this checkbox based on our property, SERVER_URL, we need to execute the custom action prior to the dialog containing the checkbox is spawned.
That would mean we have to:
0. go to "Custom Actions" page and add a PowerShell inline script, "Unsequenced"
1. in the "Dialogs" page, click on "WelcomeDlg"
2. click on the "Next" button
3. below, under "Published Events" and click "New..."
4. add the "Execute custom action" event and as argument, select the PowerShell script
5. now select the dialog containing the CheckBox
6. under "Init Events", add a new event, like so:
Now, if the value exists in the JSON, the property will be set and as a consequence, the CheckBox will be enabled.
Hope this helps!
Best regards,
Catalin
FOLLOW US
Get the latest news in Application Packaging