【问题标题】:PowerShell with WiX - Loop through certificate store and remove cert based on thumbprint带有 WiX 的 PowerShell - 循环通过证书存储并根据指纹删除证书
【发布时间】:2021-01-06 08:14:33
【问题描述】:

我有一个通过 WiX 安装程序运行的简单 PowerShell 脚本。如您所见,它会从 PFX 文件中获取指纹,然后循环遍历证书存储区,如果找到,则将其删除。

$ConfirmPreference = 'None'

# server certificate path
$serverCertFilePath = "$dataTransferCertificatePath\server.pfx"

# get thumbprint from server cert info
$serverCertInfo = Get-PfxCertificate -FilePath $serverCertFilePath
$serverThumbprint = $serverCertInfo.Thumbprint

Get-ChildItem -Path Cert:\*$serverThumbprint -Recurse | Remove-Item -Force

我已经用-Force 尝试了$ConfirmPreference = 'None'Remove-Item

当我从提升的 PowerShell 运行上述两行时它可以工作!

之后我使用 WiX 安装程序运行相同的脚本:

powershell.exe -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"

然后我得到以下信息:

该操作是在用户根存储上进行的,并且不允许使用 UI。

WiX 自定义操作调用如下:

<CustomAction Id="CA_RemoveCertificate_set"
                Property="CA_RemoveCertificate"
                Execute="immediate"
                HideTarget="yes"
                Value='"!(wix.PowerShell)" -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"' />

  <CustomAction Id="CA_RemoveCertificate"
                BinaryKey="WixCA"
                DllEntry="CAQuietExec64"
                Execute="deferred"
                Return="check"
                Impersonate="yes" />

任何帮助将不胜感激。

【问题讨论】:

    标签: powershell wix certificate custom-action


    【解决方案1】:

    您可以尝试使用Start-Process -Verb RunAs powershell.exe 打开以管理员身份运行的窗口

    看起来如果你可以用 sudo 运行它,它就会执行。

    【讨论】:

      【解决方案2】:

      为了应用修复,我在 WiX 自定义操作中调用 PowerShell 脚本时删除了 -NoLogo -NonInteractive

      对于 CA_RemoveCertificate_set 自定义操作值将是 "!(wix.PowerShell)" –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"

      <CustomAction Id="CA_RemoveCertificate_set"
                          Property="CA_RemoveCertificate"
                          Execute="immediate"
                          HideTarget="yes"
                          Value='"!(wix.PowerShell)" –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"' />
          
      <CustomAction Id="CA_RemoveCertificate"
                          BinaryKey="WixCA"
                          DllEntry="CAQuietExec64"
                          Execute="deferred"
                          Return="check"
                          Impersonate="yes" />
      

      【讨论】:

        猜你喜欢
        • 2020-12-01
        • 2019-08-04
        • 2014-07-03
        • 2016-04-20
        • 2010-10-01
        • 2019-10-02
        • 2014-07-10
        • 2013-08-09
        • 1970-01-01
        相关资源
        最近更新 更多