Installshield - checking for key in registry failed with powershell

﹥>﹥吖頭↗ 提交于 2019-12-11 08:06:11

问题


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
    }           
 }

回答1:


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




回答2:


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")


来源:https://stackoverflow.com/questions/48095563/installshield-checking-for-key-in-registry-failed-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!