我创建了Signer.vbs文件来执行此功能,下面是VBScript代码,用于为特定文件夹以数字方式签署所有文件。该文件夹包含脚本文件。
Dim sCertificate
Dim sFolder
Dim sStore
Dim objSigner
Dim objFSO
Dim objFolder
Dim colListOfFiles
Dim objFile
sCertificate = "MyCert"
sFolder = "D:\App\Project\VALab\SC\VBSigningProcess\FilesToSign"
sStore = "my"
Set objSigner = WScript.CreateObject("Scripting.Signer")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(sFolder)
Set colListOfFiles = objFolder.Files
For Each objFile in colListOfFiles
WScript.Echo "File Name : " & objFile.Path & vbnewline & "Certificate : " & sCertificate & vbnewline & "Store : " & sStore
objSigner.SignFile objFile.Path, sCertificate
Next
以上代码抛出错误在下面的行“无法找到用于解密的证书和私钥,错误代码:8009200C”
位于MMC内的“MyCert”证书。请查看下图。objSigner.SignFile objFile.Path,sCertificate