signtool.exe Error: SignerSign() failed (-2147220492/0x800403f4) when signing Excel Macro

signtool.exe Error: SignerSign() failed (-2147220492/0x800403f4) when signing Excel Macro

我目前正在尝试通过 cmd 在 Excel 和 Word 和 Powershell 脚本中签署 VBA 宏。

为此,我使用 Microsoft signtool.exe 作为 Windows 10 SDK 的一部分: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/

使用以下命令签署 Powershell 脚本效果很好:

signtool.exe sign /f "testca.pfx" /fd SHA256 /p "123456" "test.ps1"

要在 Office 文档中签署宏,还需要 "Microsoft Office Subject Interface Packages for Digitally Signing VBA Projects": https://www.microsoft.com/en-us/download/confirmation.aspx?id=56617

我下载了.exe并执行了。

使用 "regsvr32" 注册 .dll 文件也有效。 .dll 文件的路径在注册表中可见。

还安装了 Microsoft Visual C++ 2015-2019 Redistributable (x86)。

所以理论上我现在应该可以签署 Excel 宏了。 但是,我的服务器收到一条带有错误代码的错误消息,我在 Google.

中找不到任何相关信息

这是完整的输出:

The following certificates were considered:
Issued to: TestCA
Issued by: TestCA
Expires: Wed Feb 03 08:53:09 2021
SHA1 hash: E19CE363C88CDBCE677FA170008D0AB0D98A02DC

After EKU filter, one certs were left. After expiry filter, 1 certs were left. After Private Key filter, 1 certs were left. The following certificate was selected:
Issued to: TestCA
Issued by: TestCA
Expires: Wed Feb 03 08:53:09 2021
SHA1 hash: E19CE363C88CDBCE677FA170008D0AB0D98A02DC

The following additional certificates will be attached: Done Adding
Additional Store SignTool Error: An unexpected internal error has occurred.
Error information: "Error: SignerSign() failed. (-2147220492/0x800403f4)

我现在已经在不同的计算机上多次执行上述安装,均具有管理员权限和当前更新:

您可能会说 signtool.exe 是这样工作的,因为我可以在所有机器上签署 PowerShell 脚本。 但是签署宏并不总是有效。大概和接口包有关?

我希望有人以前遇到过同样的问题并且可以提供帮助。因为我对此感到疯狂。非常感谢!

好吧,这花了我很长时间,但我已经起床了 运行。如果其他人有同样的问题:

"Microsoft Office Subject Interface Packages for Digitally Signing VBA Projects".zip 包含 readme.txt 说明必须安装 "Microsoft Visual C++ Redistributal (x86)"。它后面的link下载了"Microsoft Visual C++ 2015-2019 Redistributal (x86)",这是最新的版本。

我现在已经测试了过去几年的所有可用版本,唯一可用的是 2010 版本。我不知道为什么 readme.txt 指的是不同的版本,但是这个错误和 "solution" 肯定是可以重现的。

总之,使用Visual C++ 2010,一切正常!