简体   繁体   English

Installshield - 使用PowerShell检查注册表中的密钥失败

[英]Installshield - checking for key in registry failed with powershell

I have an Installshield project with powershell CA that checks if certain registry key exists and set a property base on the result. 我有一个与powershell CA的Installshield项目,它检查是否存在某些注册表项,并根据结果设置属性。

The registry check succeeded when executing the script manually but failed (return false when get executed from Installshield. 手动执行脚本时注册表检查成功但失败(从Installshield执行时返回false

** The CA is being executed during the UI sequence (before the ExecuteAction step) - is this a problem? **在UI序列期间(在ExecuteAction步骤之前)执行CA - 这是一个问题吗?

How can I solve this issue? 我该如何解决这个问题? Is there an alternative way to check for existation of registry key with powershell custom action? 是否有另一种方法可以检查PowerShell自定义操作是否存在注册表项?

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

There is no need to do this with Powershell. Powershell没有必要这样做。 Windows installer can do this natively with the RegLocator table. Windows安装程序可以使用RegLocator表本机执行此操作。

Solved: 解决了:

Installshield indeed opens up the 32 bit version of powershell. Installshield确实打开了32位版本的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. 所以我只是要求在脚本开头获取64位版本的注册表,然后检查所需的密钥是否存在。

In order to get the 64 bit version of registry and search for my key I used: 为了获得64位版本的注册表并搜索我使用的密钥:

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

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

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