我有以下vbscript在命令行中运行时效果很好。当用鼠标双击时,愿意将其与Windows GUI结合使用。
当前设置
这是执行vbscript的当前命令 - 需要两个参数
cscript fix.vbs file.ext password
这是我的代码(fix.vbs):
Dim Arg, pfxFileName, keyFileName, cerFileName, cabFileName, keyPassword
Set Arg = WScript.Arguments
pfxFileName = Arg(0)
keyPassword = Arg(1)
keyFileName = "key.tmp"
cerFileName = "cer.tmp"
cabFileName = "cabundle.tmp"
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
return = oShell.run("cmd /C openssl pkcs12 -in " & pfxFileName & " -nocerts -out " & keyFileName & " -passin pass:" & keyPassword & " -passout pass:" & keyPassword & " | openssl pkcs12 -in " & pfxFileName & " -clcerts -nokeys -out " & cerFileName & " -passin pass:" & keyPassword & " | openssl pkcs12 -in " & pfxFileName & " -cacerts -nokeys -out " & cabFileName & " -passin pass:" & keyPassword, 0, true)
' strip all ca's except for the last block
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim reCut : Set reCut = New RegExp
reCut.Global = True
reCut.Pattern = "-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----"
Dim oMTS : Set oMTS = reCut.Execute(goFS.OpenTextFile(cabFileName).ReadAll())
Dim sBlock : sBlock = oMTS(oMTS.Count - 1).Value
' WScript.Echo sBlock
Sub SaveStringToFile(filename, text)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, 2)
f.Write text
f.Close
End Sub
SaveStringToFile cabFileName, sBlock
' build pfx file
return = oShell.run("cmd /C openssl pkcs12 -export -in " & cerFileName & " -inkey " & keyFileName & " -certfile " & cabFileName & " -out NEW-" & pfxFileName & " -password pass:" & keyPassword & " -passin pass:" & keyPassword, 0, true)
Dim WshShell, strCurDir
Set WshShell = CreateObject("WScript.Shell")
strCurDir = WshShell.CurrentDirectory
WScript.Echo vbNewLine & ">>> Thew NEW PFX file is located in " & strCurDir & "\" & "NEW-" & pfxFileName
Set oShell = Nothing
' remove files
Set obj = CreateObject("Scripting.FileSystemObject")
obj.DeleteFile(cerFileName)
obj.DeleteFile(keyFileName)
obj.DeleteFile(cabFileName)
必填项
答案 0 :(得分:3)
使用以下代码创建.vbs文件并将其放在桌面上。双击它。
PerformAction
Private Sub PerformAction()
pfxFileName = Trim(InputBox("Enter Filename:", "My VB Script"))
If pfxFileName = vbNullString Then
Exit Sub
End If
keyPassword = Trim(InputBox("Enter Password:", "My VB Script"))
If keyPassword = vbNullString Then
Exit Sub
End If
ProcessCertificate pfxFileName, keyPassword
End Sub
Private Sub ProcessCertificate(ByVal pfxFileName, ByVal keyPassword)
Dim keyFileName, cerFileName, cabFileName
keyFileName = "key.tmp"
cerFileName = "cer.tmp"
cabFileName = "cabundle.tmp"
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
return = oShell.run("cmd /C openssl pkcs12 -in " & pfxFileName & " -nocerts -out " & keyFileName & " -passin pass:" & keyPassword & " -passout pass:" & keyPassword & " | openssl pkcs12 -in " & pfxFileName & " -clcerts -nokeys -out " & cerFileName & " -passin pass:" & keyPassword & " | openssl pkcs12 -in " & pfxFileName & " -cacerts -nokeys -out " & cabFileName & " -passin pass:" & keyPassword, 0, true)
' strip all ca's except for the last block
Dim goFS: Set goFS = CreateObject("Scripting.FileSystemObject")
Dim reCut: Set reCut = New RegExp
reCut.Global = True
reCut.Pattern = "-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----"
Dim oMTS: Set oMTS = reCut.Execute(goFS.OpenTextFile(cabFileName).ReadAll())
Dim sBlock: sBlock = oMTS(oMTS.Count - 1).Value
' WScript.Echo sBlock
SaveStringToFile cabFileName, sBlock
' build pfx file
return = oShell.run("cmd /C openssl pkcs12 -export -in " & cerFileName & " -inkey " & keyFileName & " -certfile " & cabFileName & " -out NEW-" & pfxFileName & " -password pass:" & keyPassword & " -passin pass:" & keyPassword, 0, true)
Dim WshShell, strCurDir
Set WshShell = CreateObject("WScript.Shell")
strCurDir = WshShell.CurrentDirectory
WScript.Echo vbNewLine & ">>> Thew NEW PFX file is located in " & strCurDir & "\" & "NEW-" & pfxFileName
Set oShell = Nothing
' remove files
Set obj = CreateObject("Scripting.FileSystemObject")
obj.DeleteFile (cerFileName)
obj.DeleteFile (keyFileName)
obj.DeleteFile (cabFileName)
End Sub
Sub SaveStringToFile(filename, text)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, 2)
f.Write text
f.Close
End Sub