Search code examples
powershellinstallshield

Disabling Installshield's Next button with powershell


I have an Installshield project that uses powershell custom actions. In one of my dialogs, I'm asking from the user to enter username and password, then I validate the credentials (with powershell) and I want to enable the Next button only if the credentials were correct.

Can this be achieved with powershell action item? The reason I'm using powershell is that I don't know InstallScript at all.

Here is my powershell script so far:

    Function Test-UserCredential { 
    Param($username, $password) 
    Add-Type -AssemblyName System.DirectoryServices.AccountManagement 
    $ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername 
    $opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind 
    $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct 
    $Result = $pc.ValidateCredentials($username, $password).ToString() 
    $Result 
} 

$comp_username = Get-Property -Name COMPUTER_USERNAME

$comp_password = Get-Property -Name COMPUTER_PASSWORD

$result = Test-UserCredential -username $comp_username -password $comp_password

if ($result)
{
#Enable "Next" button
}

else
{
#Disable "Next" button
}

Thanks.


Solution

  • There are three things you will have to do.

    1. Choose a property that tracks whether the Next button should be enabled, and set that from your PowerShell. Typically you will set it to "1" or "" (empty string) for ease in the next step.
    2. Create Control Conditions in the dialog editor that Enable and Disable the Next button referencing the property as your condition.
    3. Separately trigger the UI to update after the powershell action completes. Unfortunately the UI does not evaluate control conditions after all property changes; it only does so after it changes a property it thinks is related. So the easiest way to do this is to add a Set Property control event that sets the property.

    Note that for clarity of step 3's relevance, it can be useful to split this into two separate properties; set one in the powershell, reflect that into another in the Set Property control event, and have control conditions that read the latter.