我有一个简单的PowerShell脚本导入证书:
$certificate_file_name = "C:\Files\Plugins\certi1.cer"
$root_cert_folder_path = 'Cert:\LocalMachine\Root'
try
{
$certificate_obj = Import-Certificate -FilePath $certificate_file_name -CertStoreLocation $root_cert_folder_path
}
catch
{
$ErrorMessage = $_.Exception.Message
write-output $ErrorMessage
}
手动运行脚本时 - 它运行正常。
另外,我有一个installshield项目有1个操作项 - 执行上面的脚本。
构建安装程序并运行它后,我收到错误`''导入证书'命令在模块'PKI'中找到,但无法加载模块。有关更多信息,请运行“Import-Module PKI”。
为什么会这样?怎么解决? `
我找到了一个解决方法:我没有使用Powershell添加我的证书,而是使用批处理,这使得它在手动运行和作为安装过程的一部分调用时都能正常工作。
批处理脚本非常简单:
Certutil -addstore -f "TrustedPublisher" "path\to\cert\file.cer"
Certutil -addstore -f "Root" "path\to\cert\file.cer"
由于Installshield仅支持运行powershell脚本,因此我使用powershell调用它来批量调用它:
cmd.exe /c 'path\to\batch\script\addCertToRootAndPublisher.bat'