W moim przypadku nie mogłem użyć PowerShell, więc napisałem ten skrypt do uruchomienia z cscript.exe że będzie Ci kciuka za pomocą wyrażenia regularnego.
If WScript.Arguments.Count() = 0 Then
WScript.Echo "Domain name to search for must be specified as first parameter."
WScript.Quit 1
End If
domain = WScript.Arguments.Item(0)
Set objShell = WScript.CreateObject ("WScript.shell")
' Get all certificate information in store.
Set objCert = objShell.Exec("certutil -store my")
certOutput = ""
Do While objCert.Status = 0
WScript.Sleep 10
Do While Not objCert.StdOut.AtEndOfStream
certOutput = certOutput & objCert.StdOut.ReadLine & vbNewLine
Loop
Loop
' Capture thumb for specified certificate using Regex.
Set thumbRegex = New RegExp
thumbRegex.Pattern = "Subject:\s+CN=" & domain & "\s*\n.*\n.*\nCert\sHash\(sha1\):\s+(.*)"
thumbRegex.IgnoreCase = True
thumbRegex.Global = False
' Verify match and trim out white space.
Set match = thumbRegex.Execute(certOutput)
result = ""
If match.Count > 0 Then
result = match.Item(0).Submatches(0)
result = Replace(result, " ", "")
WScript.Echo result
Else
WScript.Echo "The certificate for """ & domain & """ was not found."
WScript.Quit 2
End If
Skrypt w artykule robi to, co chcesz. Umieść go w pliku vbs i uruchom go. – Amnon
Dobra, zrobiłem to. Ale zależy to od CAPICOM.dll, który musi zostać zarejestrowany. Zastanawiam się, czy istnieje narzędzie korzystające bezpośrednio z Crypt API, bez zależności. – mark