Installshield-使用Powershell检查注册表中的密钥失败 [英] Installshield - checking for key in registry failed with powershell

查看:123
本文介绍了Installshield-使用Powershell检查注册表中的密钥失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有powershell CA的Installshield项目,该项目检查是否存在某些注册表项并根据结果设置属性.

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

手动执行脚本时,注册表检查成功,但失败(从Installshield执行时返回false.

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

**在UI序列期间(在ExecuteAction步骤之前)正在执行CA-这是问题吗?

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

如何解决此问题?是否有其他方法可以通过Powershell自定义操作来检查注册表项的存在?

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

推荐答案

已解决:

Installshield确实打开了32位版本的Powershell. 因此,我只是要求在脚本开始处获取注册表的64位版本,然后检查是否存在所需的密钥.

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.

为了获得64位版本的注册表并搜索我使用的密钥,

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

这篇关于Installshield-使用Powershell检查注册表中的密钥失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆