简体   繁体   English

使用Powershell禁用Installshield的“下一步”按钮

[英]Disabling Installshield's Next button with powershell

I have an Installshield project that uses powershell custom actions. 我有一个使用Powershell自定义操作的Installshield项目。 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. 在我的一个对话框中,我要求用户输入用户名和密码,然后验证凭据(使用powershell),并且仅在凭据正确时才启用“ Next按钮。

Can this be achieved with powershell action item? Powershell操作项可以实现吗? The reason I'm using powershell is that I don't know InstallScript at all. 我使用Powershell的原因是我根本不了解InstallScript。

Here is my powershell script so far: 到目前为止,这是我的powershell脚本:

    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. 谢谢。

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. 选择一个属性,该属性跟踪是否应启用“下一步”按钮,然后从PowerShell中进行设置。 Typically you will set it to "1" or "" (empty string) for ease in the next step. 通常,为便于下一步操作,将其设置为“ 1”或“”(空字符串)。
  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. 在powershell操作完成后,单独触发UI更新。 Unfortunately the UI does not evaluate control conditions after all property changes; 不幸的是,在所有属性更改之后,UI都不会评估控制条件。 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. 因此,最简单的方法是添加一个设置属性的Set Property控件事件。

Note that for clarity of step 3's relevance, it can be useful to split this into two separate properties; 请注意,为清楚起见,将步骤3分为两个单独的属性可能很有用; set one in the powershell, reflect that into another in the Set Property control event, and have control conditions that read the latter. 在Powershell中设置一个,在Set Property控件事件中将其反映为另一个,并具有读取后者的控制条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM