Hello Jason,
Unfortunately, what you want to achieve is not possible. Please allow me to explain why:
The Windows Installer documentation on the
CheckExistingTargetPath Control Event states the following:
This event notifies the installer that it has to verify that the selected path is writable. If the path cannot be written, then the event blocks further ControlEvents associated with the control.
Basically, here, you want to spawn a message box (through an event), if the path is not writable. Unfortunately, as you can see above, all the events associated with the control will be blocked, meaning that it is not quite possible to spawn a message box if the path is not writable.
Fortunately, this can be achieved through a custom approach. For instance, we can have our own script which verifies if the path is writable and, if not, spawn a message box. I have created such a script for you to use:
Code: Select all
# add the assembly so we can use the Show() method of the MessageBox class
Add-Type -AssemblyName PresentationFramework
$testFolder = "C:\Program Files\WindowsApps"
# check if our folder is actually a folder
If (Test-Path $testFolder -PathType Container){
# create a temporary test file in the folder
$testTmpFile = "testFile"+[guid]::NewGuid()
$testFile = (Join-Path $testFolder $testTmpFile)
Write-Host $testFile
Try{
[io.file]::OpenWrite($testFile).close()
Write-Host -ForegroundColor Green "Writable"
$writable = $true
Remove-Item -ErrorAction SilentlyContinue $testFile
}
Catch {
Write-Host -ForegroundColor Red "Not writable"
$writable = $false
}
}
If ($writable -eq $true){
[System.Windows.MessageBox]::Show("The path is writable")
}
else{
[System.Windows.MessageBox]::Show("The path is not writable")
}
Basically, what we are doing in our script is:
- we set our path to the folder we want to check
- check the folder's path and if the folder is actually a folder
- we create a temporary file in that folder
- we use the
File class with it's OpenWrite method to see if the file in the folder is writable
- if it's writable, spawn a message box stating that it is indeed writable
- if not, spawn a message box stating that it is not writable
As you can see, by default, I have used the %ProgramFiles%\WindowsApps folder, which is a hidden folder
that is not writable.
Now that we have our script, here is how you can implement it in Advanced Installer:
1. please go to "Custom Actions" page
2. add a
"PowerShellScriptInline" custom action without sequence (press the
"Add custom action without sequence" button which is placed to the right side of the custom action's name)
3. copy paste the code provided above into the custom action
4. now please go to
"Dialogs" page
5. select the
"Next" button. Here, please remove the
"Check if a folder path has write permissions" event and add a new one, as it follows:
Event: Execute Custom Action
Argument: your PowerShell script
Condition: leave default
This way, the message box should be spawned as per your request.
Hope this helps.
Best regards,
Catalin