Installshield - checking for key in registry faile

2019-08-14 06:40发布

I have an Installshield project with powershell CA that checks if certain registry key exists and set a property base on the result.

The registry check succeeded when executing the script manually but failed (return false when get executed from Installshield.

** The CA is being executed during the UI sequence (before the ExecuteAction step) - is this a problem?

How can I solve this issue? Is there an alternative way to check for existation of registry key with powershell custom action?

$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$keyName = "AutoAdminLogon"
if (Test-Path $registryPath)
{
    # The following line returns FALSE when executed during installation and TRUE when executed manually.
    $valueExists = (Get-ItemProperty $registryPath).PSObject.Properties.Name -contains $keyName
    if ($valueExists)
    {
        # Set property to be read in installshield
        Set-Property -Name IS_AUTO_LOGON -Value 2
    }
    else
    {
        Set-Property -Name IS_AUTO_LOGON -Value 1
    }           
 }

2条回答
We Are One
2楼-- · 2019-08-14 07:21

There is no need to do this with Powershell. Windows installer can do this natively with the RegLocator table.

查看更多
Fickle 薄情
3楼-- · 2019-08-14 07:27

Solved:

Installshield indeed opens up the 32 bit version of powershell. So I simply asked to get the 64 bit version of the registry at the beginning of the script and then checked if the required key is there.

In order to get the 64 bit version of registry and search for my key I used:

$key = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::Registry64)
$subKey =  $key.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon")
$isAutoLogon = $subKey.GetValue("AutoAdminLogon")
查看更多
登录 后发表回答