我有一个通过WiX安装程序运行的简单PowerShell脚本。正如您所看到的,它从PFX文件中获取指纹,并在证书存储中循环,如果找到它,就会将其删除。
$ConfirmPreference = 'None'
# server certificate path
$serverCertFilePath = "$dataTransferCertificatePathserver.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" />
如有任何帮助,我们将不胜感激。
您可以尝试使用Start-Process -Verb RunAs powershell.exe
打开以管理员身份运行的窗口
看起来如果你能用sudo运行这个,它就会执行。
为了应用修复程序,我在WiX自定义操作中调用PowerShell脚本时删除了-NoLogo-NonInteractive
对于CA_RemoveCertificate_set自定义操作值将为"!(wix.PowerShell(&ExecutionPolicy Unrestricted-File;删除证书.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" />