我有一个带有powershell CA的Installshield项目,用于检查是否存在某些注册表项,并根据结果设置属性。
手动执行脚本时注册表检查成功但失败(从Installshield执行时返回false
。
**在UI序列期间(ExecuteAction
步骤之前)正在执行CA - 这是一个问题吗?
我该如何解决这个问题?是否有另一种方法可以检查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
}
}
答案 0 :(得分:3)
没有必要使用Powershell执行此操作。 Windows安装程序可以使用RegLocator表本地执行此操作。
答案 1 :(得分:0)
解决:
Installshield确实打开了32位版本的PowerShell。 所以我只是要求在脚本开头获取64位版本的注册表,然后检查所需的密钥是否存在。
为了获得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")